zhengchengwu 5 gadus atpakaļ
revīzija
7dd091a6ce
100 mainītis faili ar 46778 papildinājumiem un 0 dzēšanām
  1. 1 0
      MP_verify_SwjBHSfrn5iZRUuL.txt
  2. 1995 0
      addons/ewei_shopv2/core/com/coupon.php
  3. 9 0
      addons/ewei_shopv2/core/com/h5app.php
  4. 3069 0
      addons/ewei_shopv2/core/com/perm.php
  5. 1284 0
      addons/ewei_shopv2/core/com/printer.php
  6. 230 0
      addons/ewei_shopv2/core/com/qiniu.php
  7. 230 0
      addons/ewei_shopv2/core/com/sale.php
  8. 192 0
      addons/ewei_shopv2/core/com/sendticket.php
  9. 402 0
      addons/ewei_shopv2/core/com/sms.php
  10. 16 0
      addons/ewei_shopv2/core/com/tmessage.php
  11. 473 0
      addons/ewei_shopv2/core/com/verify.php
  12. 429 0
      addons/ewei_shopv2/core/com/virtual.php
  13. 14 0
      addons/ewei_shopv2/core/com/wap.php
  14. 1840 0
      addons/ewei_shopv2/core/com/wxcard.php
  15. 9 0
      addons/ewei_shopv2/core/inc/com_model.php
  16. 33 0
      addons/ewei_shopv2/core/inc/com_processor.php
  17. 23 0
      addons/ewei_shopv2/core/inc/data_model.php
  18. 3203 0
      addons/ewei_shopv2/core/inc/functions.php
  19. 524 0
      addons/ewei_shopv2/core/inc/page.php
  20. 708 0
      addons/ewei_shopv2/core/inc/page_mobile.php
  21. 16 0
      addons/ewei_shopv2/core/inc/page_mobile_login.php
  22. 33 0
      addons/ewei_shopv2/core/inc/page_mobile_plugin.php
  23. 16 0
      addons/ewei_shopv2/core/inc/page_mobile_plugin_login.php
  24. 24 0
      addons/ewei_shopv2/core/inc/page_mobile_plugin_pf.php
  25. 21 0
      addons/ewei_shopv2/core/inc/page_system.php
  26. 126 0
      addons/ewei_shopv2/core/inc/page_web.php
  27. 17 0
      addons/ewei_shopv2/core/inc/page_web_com.php
  28. 43 0
      addons/ewei_shopv2/core/inc/page_web_plugin.php
  29. 77 0
      addons/ewei_shopv2/core/inc/plugin_model.php
  30. 49 0
      addons/ewei_shopv2/core/inc/plugin_processor.php
  31. 48 0
      addons/ewei_shopv2/core/inc/processor.php
  32. 95 0
      addons/ewei_shopv2/core/inc/receiver.php
  33. 284 0
      addons/ewei_shopv2/core/mobile/account/index.php
  34. 33 0
      addons/ewei_shopv2/core/mobile/goods/code.php
  35. 1978 0
      addons/ewei_shopv2/core/mobile/goods/detail.php
  36. 117 0
      addons/ewei_shopv2/core/mobile/goods/index.php
  37. 98 0
      addons/ewei_shopv2/core/mobile/goods/package.php
  38. 557 0
      addons/ewei_shopv2/core/mobile/goods/picker.php
  39. 178 0
      addons/ewei_shopv2/core/mobile/goods/wholesalepicker.php
  40. 148 0
      addons/ewei_shopv2/core/mobile/index.php
  41. 242 0
      addons/ewei_shopv2/core/mobile/member/activation.php
  42. 230 0
      addons/ewei_shopv2/core/mobile/member/address.php
  43. 194 0
      addons/ewei_shopv2/core/mobile/member/bind.php
  44. 638 0
      addons/ewei_shopv2/core/mobile/member/cart.php
  45. 72 0
      addons/ewei_shopv2/core/mobile/member/changepwd.php
  46. 93 0
      addons/ewei_shopv2/core/mobile/member/favorite.php
  47. 51 0
      addons/ewei_shopv2/core/mobile/member/fullback.php
  48. 65 0
      addons/ewei_shopv2/core/mobile/member/history.php
  49. 205 0
      addons/ewei_shopv2/core/mobile/member/index.php
  50. 132 0
      addons/ewei_shopv2/core/mobile/member/info.php
  51. 53 0
      addons/ewei_shopv2/core/mobile/member/log.php
  52. 47 0
      addons/ewei_shopv2/core/mobile/member/notice.php
  53. 188 0
      addons/ewei_shopv2/core/mobile/member/rank.php
  54. 387 0
      addons/ewei_shopv2/core/mobile/member/recharge.php
  55. 244 0
      addons/ewei_shopv2/core/mobile/member/withdraw.php
  56. 107 0
      addons/ewei_shopv2/core/mobile/order/comment.php
  57. 5130 0
      addons/ewei_shopv2/core/mobile/order/create.php
  58. 902 0
      addons/ewei_shopv2/core/mobile/order/index.php
  59. 217 0
      addons/ewei_shopv2/core/mobile/order/op.php
  60. 1423 0
      addons/ewei_shopv2/core/mobile/order/pay.php
  61. 253 0
      addons/ewei_shopv2/core/mobile/order/pay_alipay.php
  62. 298 0
      addons/ewei_shopv2/core/mobile/order/refund.php
  63. 335 0
      addons/ewei_shopv2/core/mobile/order/single_refund.php
  64. 426 0
      addons/ewei_shopv2/core/mobile/sale/coupon/detail.php
  65. 556 0
      addons/ewei_shopv2/core/mobile/sale/coupon/index.php
  66. 790 0
      addons/ewei_shopv2/core/mobile/sale/coupon/my.php
  67. 34 0
      addons/ewei_shopv2/core/mobile/sale/coupon/quickget.php
  68. 19 0
      addons/ewei_shopv2/core/mobile/sale/coupon/show.php
  69. 37 0
      addons/ewei_shopv2/core/mobile/sale/coupon/util.php
  70. 399 0
      addons/ewei_shopv2/core/mobile/sale/sendticket/share.php
  71. 100 0
      addons/ewei_shopv2/core/mobile/shop/category.php
  72. 29 0
      addons/ewei_shopv2/core/mobile/shop/cityexpress.php
  73. 55 0
      addons/ewei_shopv2/core/mobile/shop/notice.php
  74. 68 0
      addons/ewei_shopv2/core/mobile/store/index.php
  75. 42 0
      addons/ewei_shopv2/core/mobile/store/map.php
  76. 41 0
      addons/ewei_shopv2/core/mobile/store/selector.php
  77. 13 0
      addons/ewei_shopv2/core/mobile/util/empty.php
  78. 14 0
      addons/ewei_shopv2/core/mobile/util/task.php
  79. 120 0
      addons/ewei_shopv2/core/mobile/util/uploader.php
  80. 158 0
      addons/ewei_shopv2/core/mobile/verify/index.php
  81. 116 0
      addons/ewei_shopv2/core/mobile/verify/page.php
  82. 147 0
      addons/ewei_shopv2/core/mobile/verify/verifygoods.php
  83. 1021 0
      addons/ewei_shopv2/core/mobile/verify/verifyorder.php
  84. 431 0
      addons/ewei_shopv2/core/mobile/verifygoods/index.php
  85. 88 0
      addons/ewei_shopv2/core/model/account.php
  86. 595 0
      addons/ewei_shopv2/core/model/bind.php
  87. 146 0
      addons/ewei_shopv2/core/model/cache.php
  88. 1784 0
      addons/ewei_shopv2/core/model/common.php
  89. 31 0
      addons/ewei_shopv2/core/model/cookie.php
  90. 281 0
      addons/ewei_shopv2/core/model/dispatch.php
  91. 162 0
      addons/ewei_shopv2/core/model/excel.php
  92. 20 0
      addons/ewei_shopv2/core/model/express.php
  93. 1731 0
      addons/ewei_shopv2/core/model/finance.php
  94. 1203 0
      addons/ewei_shopv2/core/model/goods.php
  95. 1082 0
      addons/ewei_shopv2/core/model/member.php
  96. 84 0
      addons/ewei_shopv2/core/model/message.php
  97. 2174 0
      addons/ewei_shopv2/core/model/notice.php
  98. 2544 0
      addons/ewei_shopv2/core/model/order.php
  99. 89 0
      addons/ewei_shopv2/core/model/ordergoods.php
  100. 0 0
      addons/ewei_shopv2/core/model/pay.php

+ 1 - 0
MP_verify_SwjBHSfrn5iZRUuL.txt Parādīt failu

@@ -0,0 +1 @@
1
+SwjBHSfrn5iZRUuL

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1995 - 0
addons/ewei_shopv2/core/com/coupon.php


+ 9 - 0
addons/ewei_shopv2/core/com/h5app.php Parādīt failu

@@ -0,0 +1,9 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class H5app_EweiShopV2ComModel extends ComModel
7
+{}
8
+
9
+?>

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3069 - 0
addons/ewei_shopv2/core/com/perm.php


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1284 - 0
addons/ewei_shopv2/core/com/printer.php


+ 230 - 0
addons/ewei_shopv2/core/com/qiniu.php Parādīt failu

@@ -0,0 +1,230 @@
1
+<?php
2
+function qiniuClassLoader($class)
3
+{
4
+	$path = str_replace('\\', DIRECTORY_SEPARATOR, $class);
5
+	$file = IA_ROOT . '/framework/library/qiniu/src/' . $path . '.php';
6
+
7
+	if (file_exists($file)) {
8
+		require_once $file;
9
+	}
10
+}
11
+
12
+if (!defined('IN_IA')) {
13
+	exit('Access Denied');
14
+}
15
+
16
+class Qiniu_EweiShopV2ComModel extends ComModel
17
+{
18
+	public function save($url, $config = NULL, $enforce = false)
19
+	{
20
+		global $_W;
21
+		global $_GPC;
22
+		$oldurl = $url;
23
+		set_time_limit(0);
24
+
25
+		if (empty($url)) {
26
+			return '';
27
+		}
28
+
29
+		$ext = strrchr($url, '.');
30
+		if ($ext != '.jpeg' && $ext != '.gif' && $ext != '.jpg' && $ext != '.png') {
31
+			return '';
32
+		}
33
+
34
+		if (!$config) {
35
+			$config = $this->getConfig();
36
+		}
37
+
38
+		if (empty($config)) {
39
+			if (!empty($_W['setting']['remote']['type']) && !(strexists($url, 'http:') || strexists($url, 'https:'))) {
40
+				if (is_file(ATTACHMENT_ROOT . $url)) {
41
+					load()->func('file');
42
+					$remotestatus = file_remote_upload($url, false);
43
+
44
+					if (is_error($remotestatus)) {
45
+						return $url;
46
+					}
47
+				}
48
+
49
+				$remoteurl = $_W['attachurl_remote'] . $url;
50
+				return $remoteurl;
51
+			}
52
+
53
+			return $url;
54
+		}
55
+
56
+		if (strexists($url, $config['url'])) {
57
+			return $url;
58
+		}
59
+
60
+		if (strexists($url, '../addons/ewei_shopv2')) {
61
+			$url = str_replace('../addons/ewei_shopv2', 'addons/ewei_shopv2', $url);
62
+		}
63
+
64
+		if (!strexists($url, 'addons/ewei_shopv2')) {
65
+			$url = tomedia($url);
66
+		}
67
+
68
+		if (!empty($_W['setting']['remote']['type'])) {
69
+			$enforce = true;
70
+		}
71
+
72
+		$outlinkEnforce = false;
73
+
74
+		if (!strexists($url, $_W['siteroot'])) {
75
+			if (strexists($url, 'http:') || strexists($url, 'https:')) {
76
+				if (!$enforce) {
77
+					return $url;
78
+				}
79
+
80
+				$outlinkEnforce = true;
81
+			}
82
+		}
83
+
84
+		if (!$outlinkEnforce) {
85
+			if (strexists($url, 'http:') || strexists($url, 'https:')) {
86
+				if (!strexists($url, 'addons/ewei_shopv2')) {
87
+					$url = ATTACHMENT_ROOT . str_replace($_W['siteroot'] . 'attachment/', '', str_replace($_W['attachurl'], '', $url));
88
+				}
89
+				else {
90
+					$url = IA_ROOT . '/' . $url;
91
+				}
92
+			}
93
+			else {
94
+				$outlinkEnforce = true;
95
+
96
+				if (strexists($url, 'addons/ewei_shopv2')) {
97
+					$url = IA_ROOT . '/' . $url;
98
+					$outlinkEnforce = false;
99
+				}
100
+			}
101
+		}
102
+
103
+		$key = ($outlinkEnforce ? md5($url) : md5_file($url)) . $ext;
104
+
105
+		if ($outlinkEnforce) {
106
+			$local = ATTACHMENT_ROOT . 'ewei_shopv2_temp/';
107
+			load()->func('file');
108
+
109
+			if (!is_dir($local)) {
110
+				mkdirs($local);
111
+			}
112
+
113
+			$filename = $local . $key;
114
+			load()->func('communication');
115
+			$resp = ihttp_get($url);
116
+
117
+			if ($resp['code'] != 200) {
118
+				return $oldurl;
119
+			}
120
+
121
+			file_put_contents($filename, $resp['content']);
122
+			$url = $filename;
123
+		}
124
+
125
+		if (!function_exists('classLoader')) {
126
+			require_once IA_ROOT . '/framework/library/qiniu/autoload.php';
127
+		}
128
+		else {
129
+			spl_autoload_register('qiniuClassLoader');
130
+			require_once IA_ROOT . '/framework/library/qiniu/src/Qiniu/functions.php';
131
+		}
132
+
133
+		$auth = new \Qiniu\Auth($config['access_key'], $config['secret_key']);
134
+
135
+		if (is_callable('\\Qiniu\\Zone::zone0')) {
136
+			$zone = \Qiniu\Zone::zone0();
137
+
138
+			if ($config['zone'] == 'zone1') {
139
+				$zone = \Qiniu\Zone::zone1();
140
+			}
141
+
142
+			$uploadmgr = new \Qiniu\Storage\UploadManager(new \Qiniu\Config($zone));
143
+			$putpolicy = \Qiniu\base64_urlSafeEncode(json_encode(array('scope' => $config['bucket'] . ':' . $url)));
144
+			$uploadtoken = $auth->uploadToken($config['bucket'], $key, 3600, $putpolicy);
145
+		}
146
+		else {
147
+			$uploadmgr = new \Qiniu\Storage\UploadManager();
148
+			$uploadtoken = $auth->uploadToken($config['bucket'], $key, 3600);
149
+		}
150
+
151
+		$ret = $uploadmgr->putFile($uploadtoken, $key, $url);
152
+
153
+		if (!empty($ret[1])) {
154
+			$err = $ret[1]->getResponse()->error;
155
+			return error(1, $err);
156
+		}
157
+
158
+		if ($outlinkEnforce) {
159
+			@unlink($url);
160
+		}
161
+
162
+		if (strexists($config['url'], 'http:') || strexists($config['url'], 'https:')) {
163
+			return trim($config['url']) . '/' . $ret[0]['key'];
164
+		}
165
+
166
+		return 'http://' . trim($config['url']) . '/' . $ret[0]['key'];
167
+	}
168
+
169
+	/**
170
+     * 获取配置
171
+     * @return boolean
172
+     */
173
+	public function getConfig()
174
+	{
175
+		global $_W;
176
+		global $_GPC;
177
+		$config = false;
178
+		$set = m('common')->getSysset('qiniu');
179
+		if (isset($set['user']) && is_array($set['user']) && !empty($set['user']['upload']) && !empty($set['user']['access_key']) && !empty($set['user']['secret_key']) && !empty($set['user']['bucket']) && !empty($set['user']['url'])) {
180
+			$config = $set['user'];
181
+		}
182
+		else {
183
+			$path = IA_ROOT . '/addons/ewei_shopv2/data/global';
184
+			$admin = m('cache')->getArray('qiniu', 'global');
185
+			if (empty($admin['upload']) && is_file($path . '/qiniu.cache')) {
186
+				$data_authcode = authcode(file_get_contents($path . '/qiniu.cache'), 'DECODE', 'global');
187
+				$admin = json_decode($data_authcode, true);
188
+			}
189
+
190
+			if (is_array($admin) && !empty($admin['upload']) && !empty($admin['access_key']) && !empty($admin['secret_key']) && !empty($admin['bucket']) && !empty($admin['url'])) {
191
+				$config = $admin;
192
+			}
193
+		}
194
+
195
+		return $config;
196
+	}
197
+
198
+	public function deletewqfile($attachment)
199
+	{
200
+		global $_W;
201
+		$attachment = trim($attachment);
202
+		$media = pdo_get('core_attachment', array('uniacid' => $_W['uniacid'], 'attachment' => $attachment));
203
+
204
+		if (empty($media)) {
205
+			return false;
206
+		}
207
+
208
+		if (empty($_W['isfounder']) && $_W['role'] != 'manager') {
209
+			return false;
210
+		}
211
+
212
+		load()->func('file');
213
+
214
+		if (!empty($_W['setting']['remote']['type'])) {
215
+			$status = file_remote_delete($media['attachment']);
216
+		}
217
+		else {
218
+			$status = file_delete($media['attachment']);
219
+		}
220
+
221
+		if (is_error($status)) {
222
+			return $status['message'];
223
+		}
224
+
225
+		pdo_delete('core_attachment', array('uniacid' => $_W['uniacid'], 'id' => $media['id']));
226
+		return true;
227
+	}
228
+}
229
+
230
+?>

+ 230 - 0
addons/ewei_shopv2/core/com/sale.php Parādīt failu

@@ -0,0 +1,230 @@
1
+<?php
2
+function sort_enoughs($a, $b)
3
+{
4
+	$enough1 = floatval($a['enough']);
5
+	$enough2 = floatval($b['enough']);
6
+
7
+	if ($enough1 == $enough2) {
8
+		return 0;
9
+	}
10
+
11
+	return $enough1 < $enough2 ? 1 : -1;
12
+}
13
+
14
+if (!defined('IN_IA')) {
15
+	exit('Access Denied');
16
+}
17
+
18
+class Sale_EweiShopV2ComModel extends ComModel
19
+{
20
+	public function getEnoughsGoods()
21
+	{
22
+		global $_W;
23
+		global $_S;
24
+		$set = $_S['sale'];
25
+		$goodsids = $set['goodsids'];
26
+		return $goodsids;
27
+	}
28
+
29
+	public function getEnoughs()
30
+	{
31
+		global $_W;
32
+		global $_S;
33
+		$set = $_S['sale'];
34
+		$allenoughs = array();
35
+		$enoughs = $set['enoughs'];
36
+		if (0 < floatval($set['enoughmoney']) && 0 < floatval($set['enoughdeduct'])) {
37
+			$allenoughs[] = array('enough' => floatval($set['enoughmoney']), 'money' => floatval($set['enoughdeduct']));
38
+		}
39
+
40
+		if (is_array($enoughs)) {
41
+			foreach ($enoughs as $e) {
42
+				if (0 < floatval($e['enough']) && 0 < floatval($e['give'])) {
43
+					$allenoughs[] = array('enough' => floatval($e['enough']), 'money' => floatval($e['give']));
44
+				}
45
+			}
46
+		}
47
+
48
+		usort($allenoughs, 'sort_enoughs');
49
+		return $allenoughs;
50
+	}
51
+
52
+	public function getEnoughFree()
53
+	{
54
+		global $_W;
55
+		global $_S;
56
+		$set = $_S['sale'];
57
+
58
+		if (!empty($set['enoughfree'])) {
59
+			return 0 < $set['enoughorder'] ? $set['enoughorder'] : -1;
60
+		}
61
+
62
+		return false;
63
+	}
64
+
65
+	public function getRechargeActivity()
66
+	{
67
+		global $_S;
68
+		$set = $_S['sale'];
69
+		$recharges = iunserializer($set['recharges']);
70
+
71
+		if (is_array($recharges)) {
72
+			usort($recharges, 'sort_enoughs');
73
+			return $recharges;
74
+		}
75
+
76
+		return false;
77
+	}
78
+	
79
+	public function setRechargeActivity($log)
80
+	{
81
+		global $_W;
82
+		global $_S;
83
+		$set = m('common')->getPluginset('sale');
84
+		$recharges = iunserializer($set['recharges']);
85
+		$credit2 = 0;
86
+		$enough = 0;
87
+		$give = '';
88
+
89
+		if (is_array($recharges)) {
90
+			usort($recharges, 'sort_enoughs');
91
+
92
+			foreach ($recharges as $r) {
93
+				if (empty($r['enough']) || empty($r['give'])) {
94
+					continue;
95
+				}
96
+
97
+				if (floatval($r['enough']) <= $log['money']) {
98
+					if (strexists($r['give'], '%')) {
99
+						$credit2 = round(floatval(str_replace('%', '', $r['give'])) / 100 * $log['money'], 2);
100
+					}
101
+					else {
102
+						$credit2 = round(floatval($r['give']), 2);
103
+					}
104
+
105
+					$enough = floatval($r['enough']);
106
+					$give = $r['give'];
107
+					break;
108
+				}
109
+			}
110
+		}
111
+
112
+		if (0 < $credit2) {
113
+			m('member')->setCredit($log['openid'], 'credit2', $credit2, array('0', $_S['shop']['name'] . '充值满' . $enough . '赠送' . $give, '现金活动'));
114
+			pdo_update('ewei_shop_member_log', array('gives' => $credit2), array('id' => $log['id']));
115
+		}
116
+
117
+		$this->getCredit1($log['openid'], $log['money'], 21, 2);
118
+	}
119
+	public function getCredit1($openid, $price = 0, $paytype = 1, $type = 1, $refund = 0, $desc = '')
120
+	{
121
+		global $_W;
122
+		$type = intval($type);
123
+		if (empty($openid) || empty($price) || empty($type)) {
124
+			return 0;
125
+		}
126
+
127
+		$data = m('common')->getPluginset('sale');
128
+		$credit1 = iunserializer($data['credit1']);
129
+
130
+		if ($type == '1') {
131
+			$name = '积分活动购物送积分';
132
+			$enoughs = empty($credit1['enough1']) ? array() : $credit1['enough1'];
133
+
134
+			if (empty($credit1['paytype'])) {
135
+				return 0;
136
+			}
137
+
138
+			if (!empty($credit1['paytype']) && !in_array($paytype, array_keys($credit1['paytype']))) {
139
+				return 0;
140
+			}
141
+		}
142
+		else {
143
+			if ($type = '2') {
144
+				$name = '积分活动充值送积分';
145
+				$enoughs = empty($credit1['enough2']) ? array() : $credit1['enough2'];
146
+			}
147
+		}
148
+
149
+		if (!empty($desc)) {
150
+			$name = $desc;
151
+		}
152
+
153
+		$allenoughs = array();
154
+
155
+		if (is_array($enoughs)) {
156
+			foreach ($enoughs as $e) {
157
+				if (floatval($e['enough' . $type . '_1']) <= $price && $price <= floatval($e['enough' . $type . '_2'])) {
158
+					if (0 < floatval($e['give' . $type])) {
159
+						$allenoughs[] = floatval($e['give' . $type]);
160
+					}
161
+				}
162
+			}
163
+		}
164
+
165
+		$money = 0;
166
+
167
+		if (!empty($allenoughs)) {
168
+			$money = (double) max($allenoughs);
169
+		}
170
+
171
+		if (0 < $money) {
172
+			$money *= $price;
173
+			$money = floor($money);
174
+
175
+			if (empty($refund)) {
176
+				m('member')->setCredit($openid, 'credit1', $money, $name . ': ' . $money . '积分');
177
+			}
178
+			else {
179
+				m('member')->setCredit($openid, 'credit1', 0 - $money, $name . '退款 : ' . (0 - $money) . '积分');
180
+			}
181
+		}
182
+
183
+		return $money;
184
+	}
185
+
186
+	public function getPeerPay()
187
+	{
188
+		global $_W;
189
+		$res = array(
190
+			0                   => '万水千山总是情,这单帮我一定行',
191
+			1                   => array('无名侠', '支持一下,么么哒!'),
192
+			'self_peerpay'      => 0,
193
+			'peerpay_price'     => 0,
194
+			'peerpay_privilege' => 0
195
+			);
196
+		$data = m('common')->getPluginset('sale');
197
+		$data = $data['peerpay'];
198
+
199
+		if (empty($data['open'])) {
200
+			return false;
201
+		}
202
+
203
+		$enough1 = empty($data['enough1']) ? array() : $data['enough1'];
204
+		$enough2 = empty($data['enough2']) ? array() : $data['enough2'];
205
+
206
+		if (!empty($enough1)) {
207
+			$key = array_rand($enough1);
208
+			$res[0] = $enough1[$key];
209
+		}
210
+
211
+		if (!empty($enough2)) {
212
+			$key = array_rand($enough2);
213
+			$res[1][0] = $enough2[$key]['enough2_1'];
214
+			$res[1][1] = $enough2[$key]['enough2_2'];
215
+		}
216
+
217
+		if (!empty($data['self_peerpay'])) {
218
+			$res['self_peerpay'] = (double) $data['self_peerpay'];
219
+		}
220
+
221
+		if (!empty($data['peerpay_price'])) {
222
+			$res['peerpay_price'] = (double) $data['peerpay_price'];
223
+			$res['peerpay_privilege'] = (double) $data['peerpay_privilege'];
224
+		}
225
+
226
+		return $res;
227
+	}
228
+}
229
+
230
+?>

+ 192 - 0
addons/ewei_shopv2/core/com/sendticket.php Parādīt failu

@@ -0,0 +1,192 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Sendticket_EweiShopV2ComModel extends ComModel
7
+{
8
+	public function getInfo()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$openid = $_W['openid'];
13
+
14
+		if (!com('coupon')) {
15
+			return false;
16
+		}
17
+
18
+		$member = m('member')->getMember($_W['openid']);
19
+		$condition = ' WHERE uniacid = :uniacid AND openid = :openid';
20
+		$paramso = array(':uniacid' => intval($_W['uniacid']), ':openid' => trim($openid));
21
+		$osql = 'SELECT * FROM ' . tablename('ewei_shop_order') . $condition;
22
+		$order = pdo_fetchall($osql, $paramso);
23
+
24
+		if (empty($order)) {
25
+			$sql2 = 'SELECT * FROM ' . tablename('ewei_shop_sendticket') . ' WHERE uniacid = ' . intval($_W['uniacid']);
26
+			$ticket = pdo_fetch($sql2);
27
+
28
+			if ($ticket['status'] == 1) {
29
+				if ($ticket['expiration'] == 1) {
30
+					if ($ticket['endtime'] < TIMESTAMP) {
31
+						$status = array('status' => 0);
32
+						pdo_update('ewei_shop_sendticket', $status, array('id' => $ticket['id']));
33
+						return false;
34
+					}
35
+
36
+					$cpinfo = $this->getCoupon($ticket['cpid']);
37
+
38
+					if (empty($cpinfo)) {
39
+						return false;
40
+					}
41
+
42
+					$insert = $this->insertDraw($openid, $cpinfo);
43
+
44
+					if ($insert) {
45
+						if (count($cpinfo) == count($cpinfo, 1)) {
46
+							$status = $this->sendTicket($openid, $cpinfo['id'], 14);
47
+
48
+							if (!$status) {
49
+								return false;
50
+							}
51
+
52
+							$cpinfo['did'] = $status;
53
+						}
54
+						else {
55
+							foreach ($cpinfo as $cpk => $cpv) {
56
+								$status = $this->sendTicket($openid, $cpv['id'], 14);
57
+
58
+								if (!$status) {
59
+									return false;
60
+								}
61
+
62
+								$cpinfo[$cpk]['did'] = $status;
63
+							}
64
+						}
65
+
66
+						return $cpinfo;
67
+					}
68
+
69
+					return false;
70
+				}
71
+
72
+				$cpinfo = $this->getCoupon($ticket['cpid']);
73
+
74
+				if (empty($cpinfo)) {
75
+					return false;
76
+				}
77
+
78
+				$insert = $this->insertDraw($openid, $cpinfo);
79
+
80
+				if ($insert) {
81
+					if (count($cpinfo) == count($cpinfo, 1)) {
82
+						$status = $this->sendTicket($openid, $cpinfo['id'], 14);
83
+
84
+						if (!$status) {
85
+							return false;
86
+						}
87
+
88
+						$cpinfo['did'] = $status;
89
+					}
90
+					else {
91
+						foreach ($cpinfo as $cpk => $cpv) {
92
+							$status = $this->sendTicket($openid, $cpv['id'], 14);
93
+
94
+							if (!$status) {
95
+								return false;
96
+							}
97
+
98
+							$cpinfo[$cpk]['did'] = $status;
99
+						}
100
+					}
101
+
102
+					return $cpinfo;
103
+				}
104
+
105
+				return false;
106
+			}
107
+
108
+			if ($ticket['status'] == 0) {
109
+				return false;
110
+			}
111
+		}
112
+		else {
113
+			return false;
114
+		}
115
+	}
116
+
117
+	public function getCoupon($cpid)
118
+	{
119
+		global $_W;
120
+		global $_GPC;
121
+
122
+		if (strpos($cpid, ',')) {
123
+			$cpids = explode(',', $cpid);
124
+		}
125
+		else {
126
+			$cpids = $cpid;
127
+		}
128
+
129
+		if (is_array($cpids)) {
130
+			$cpinfo = array();
131
+
132
+			foreach ($cpids as $cpk => $cpv) {
133
+				$cpsql = 'SELECT * FROM ' . tablename('ewei_shop_coupon') . ' WHERE uniacid = ' . intval($_W['uniacid']) . ' AND id = ' . intval($cpv);
134
+				$list = pdo_fetch($cpsql);
135
+
136
+				if ($list['timelimit'] == 1) {
137
+					if (TIMESTAMP < $list['timeend']) {
138
+						$cpinfo[$cpk] = $list;
139
+					}
140
+				}
141
+				else {
142
+					if ($list['timelimit'] == 0) {
143
+						$cpinfo[$cpk] = $list;
144
+					}
145
+				}
146
+			}
147
+
148
+			return $cpinfo;
149
+		}
150
+
151
+		$cpsql = 'SELECT * FROM ' . tablename('ewei_shop_coupon') . ' WHERE uniacid = ' . intval($_W['uniacid']) . ' AND id = ' . intval($cpid);
152
+		$cpinfo = pdo_fetch($cpsql);
153
+		return $cpinfo;
154
+	}
155
+
156
+	public function sendTicket($openid, $couponid, $gettype = 0)
157
+	{
158
+		global $_W;
159
+		global $_GPC;
160
+		$couponlog = array('uniacid' => $_W['uniacid'], 'openid' => $openid, 'logno' => m('common')->createNO('coupon_log', 'logno', 'CC'), 'couponid' => $couponid, 'status' => 1, 'paystatus' => -1, 'creditstatus' => -1, 'createtime' => time(), 'getfrom' => 3);
161
+		$log = pdo_insert('ewei_shop_coupon_log', $couponlog);
162
+		$data = array('uniacid' => $_W['uniacid'], 'openid' => $openid, 'couponid' => $couponid, 'gettype' => $gettype, 'gettime' => time());
163
+		$data = pdo_insert('ewei_shop_coupon_data', $data);
164
+		$did = pdo_insertid();
165
+		if ($log && $data) {
166
+			return $did;
167
+		}
168
+
169
+		return false;
170
+	}
171
+
172
+	public function share($money)
173
+	{
174
+		$activity = $this->activity($money);
175
+
176
+		if (!empty($activity)) {
177
+			return true;
178
+		}
179
+
180
+		return false;
181
+	}
182
+
183
+	public function activity($money)
184
+	{
185
+		global $_W;
186
+		$sql = 'SELECT * FROM ' . tablename('ewei_shop_sendticket_share') . ' WHERE uniacid = ' . intval($_W['uniacid']) . ' AND status = 1 AND (enough = ' . $money . ' OR enough <= ' . $money . ') AND (expiration = 0 OR (expiration = 1 AND endtime >= ' . TIMESTAMP . ')) ORDER BY enough DESC,createtime DESC LIMIT 1';
187
+		$activity = pdo_fetch($sql);
188
+		return $activity;
189
+	}
190
+}
191
+
192
+?>

+ 402 - 0
addons/ewei_shopv2/core/com/sms.php Parādīt failu

@@ -0,0 +1,402 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Sms_EweiShopV2ComModel extends ComModel
7
+{
8
+	/**
9
+     * 发送短信
10
+     * @param int $mobile 手机号
11
+     * @param string $tplid 商城短信模板iID
12
+     * @param array $data  发送数据  $replace=true $data替换模板数据  $replace=false 则直接使用$data作为发送数据
13
+     * @param true $replace  是否替换数据
14
+     * @return array  return status
15
+     */
16
+	public function send($mobile, $tplid, $data, $replace = true)
17
+	{
18
+		global $_W;
19
+		$smsset = $this->sms_set();
20
+		$template = $this->sms_verify($tplid, $smsset);
21
+
22
+		if (empty($template['status'])) {
23
+			return $template;
24
+		}
25
+
26
+		if ($template['type'] == 'aliyun_new' || $template['type'] == 'aliyun') {
27
+			foreach ($data as $key => $val) {
28
+				if (20 < mb_strlen($val)) {
29
+					$data[$key] = mb_substr($val, 0, 7, 'UTF-8') . '....' . mb_substr($val, -8, NULL, 'UTF-8');
30
+				}
31
+			}
32
+		}
33
+
34
+		$params = $this->sms_data($template['type'], $data, $replace, $template);
35
+
36
+		if ($template['type'] == 'juhe') {
37
+			$data = array('mobile' => $mobile, 'tpl_id' => $template['smstplid'], 'tpl_value' => $params, 'key' => $smsset['juhe_key']);
38
+			load()->func('communication');
39
+			$result = ihttp_post('http://v.juhe.cn/sms/send', $data);
40
+			$result = json_decode($result['content'], true);
41
+			if (empty($result) || isset($result['error_code']) && 0 < $result['error_code']) {
42
+				return array('status' => 0, 'message' => '短信发送失败(' . $result['error_code'] . '):' . $result['reason']);
43
+			}
44
+		}
45
+		else if ($template['type'] == 'dayu') {
46
+			include_once EWEI_SHOPV2_VENDOR . 'dayu/TopSdk.php';
47
+			$dayuClient = new TopClient();
48
+			$dayuClient->appkey = $smsset['dayu_key'];
49
+			$dayuClient->secretKey = $smsset['dayu_secret'];
50
+			$dayuRequest = new AlibabaAliqinFcSmsNumSendRequest();
51
+			$dayuRequest->setSmsType('normal');
52
+			$dayuRequest->setSmsFreeSignName($template['smssign']);
53
+			$dayuRequest->setSmsParam($params);
54
+			$dayuRequest->setRecNum('' . $mobile);
55
+			$dayuRequest->setSmsTemplateCode($template['smstplid']);
56
+			$dayuResult = $dayuClient->execute($dayuRequest);
57
+			$dayuResult = (array) $dayuResult;
58
+			if (empty($dayuResult) || !empty($dayuResult['code'])) {
59
+				return array('status' => 0, 'message' => '短信发送失败(' . $dayuResult['sub_msg'] . '/code: ' . $dayuResult['code'] . '/sub_code: ' . $dayuResult['sub_code'] . ')');
60
+			}
61
+		}
62
+		else if ($template['type'] == 'aliyun') {
63
+			load()->func('communication');
64
+			$paramstr = http_build_query(array('ParamString' => $params, 'RecNum' => $mobile, 'SignName' => $template['smssign'], 'TemplateCode' => $template['smstplid']));
65
+			$header = array('Authorization' => 'APPCODE ' . $smsset['aliyun_appcode']);
66
+			$request = ihttp_request('http://sms.market.alicloudapi.com/singleSendSms?' . $paramstr, '', $header);
67
+			$result = json_decode($request['content'], true);
68
+			if (!$result['success'] || $request['code'] != 200) {
69
+				if ($request['code'] != 200) {
70
+					$result['message'] = $request['headers']['X-Ca-Error-Message'];
71
+				}
72
+
73
+				return array('status' => 0, 'message' => '短信发送失败(错误信息: ' . $result['message'] . ')');
74
+			}
75
+		}
76
+		else if ($template['type'] == 'aliyun_new') {
77
+			include_once EWEI_SHOPV2_VENDOR . 'aliyun/sendSms.php';
78
+			$option = array('keyid' => $smsset['aliyun_new_keyid'], 'keysecret' => $smsset['aliyun_new_keysecret'], 'phonenumbers' => $mobile, 'signname' => $template['smssign'], 'templatecode' => $template['smstplid'], 'templateparam' => $params);
79
+			$result = sendSms($option);
80
+
81
+			if ($result['Message'] != 'OK') {
82
+				return array('status' => 0, 'message' => '短信发送失败(错误信息: ' . $result['Message'] . ')');
83
+			}
84
+		}
85
+		else if ($template['type'] == 'emay') {
86
+			include_once EWEI_SHOPV2_VENDOR . 'emay/SMSUtil.php';
87
+			$balance = $this->sms_num('emay', $smsset);
88
+
89
+			if ($balance <= 0) {
90
+				return array('status' => 0, 'message' => '短信发送失败(亿美软通余额不足, 当前余额' . $balance . ')');
91
+			}
92
+
93
+			$emayClient = new SMSUtil($smsset['emay_url'], $smsset['emay_sn'], $smsset['emay_pw'], $smsset['emay_sk'], array('proxyhost' => $smsset['emay_phost'], 'proxyport' => $smsset['pport'], 'proxyusername' => $smsset['puser'], 'proxypassword' => $smsset['ppw']), $smsset['emay_out'], $smsset['emay_outresp']);
94
+			$emayResult = $emayClient->send($mobile, '【' . $template['smssign'] . '】' . $params);
95
+
96
+			if (!empty($emayResult)) {
97
+				return array('status' => 0, 'message' => '短信发送失败(错误信息: ' . $emayResult . ')');
98
+			}
99
+		}
100
+		else {
101
+			return array('status' => 0, 'message' => '短信发送失败(未识别的短信服务商)');
102
+		}
103
+
104
+		return array('status' => 1);
105
+	}
106
+
107
+	public function sms_set()
108
+	{
109
+		global $_W;
110
+		return pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_sms_set') . ' WHERE uniacid=:uniacid ', array(':uniacid' => $_W['uniacid']));
111
+	}
112
+
113
+	public function sms_temp()
114
+	{
115
+		global $_W;
116
+		$list = pdo_fetchall('SELECT id, `type`, `name` FROM ' . tablename('ewei_shop_sms') . ' WHERE status=1 and uniacid=:uniacid ', array(':uniacid' => $_W['uniacid']));
117
+
118
+		foreach ($list as $i => &$item) {
119
+			if ($item['type'] == 'juhe') {
120
+				$item['name'] = '[聚合]' . $item['name'];
121
+			}
122
+			else if ($item['type'] == 'dayu') {
123
+				$item['name'] = '[大于]' . $item['name'];
124
+			}
125
+			else if ($item['type'] == 'aliyun') {
126
+				$item['name'] = '[阿里云]' . $item['name'];
127
+			}
128
+			else if ($item['type'] == 'aliyun_new') {
129
+				$item['name'] = '[新版阿里云]' . $item['name'];
130
+			}
131
+			else {
132
+				if ($item['type'] == 'emay') {
133
+					$item['name'] = '[亿美]' . $item['name'];
134
+				}
135
+			}
136
+		}
137
+
138
+		unset($item);
139
+		return $list;
140
+	}
141
+
142
+	public function sms_num($type, $smsset = NULL)
143
+	{
144
+		if (empty($type)) {
145
+			return NULL;
146
+		}
147
+
148
+		if (empty($smsset) || !is_array($smsset)) {
149
+			$smsset = $this->sms_set();
150
+		}
151
+
152
+		if ($type == 'emay') {
153
+			include_once EWEI_SHOPV2_VENDOR . 'emay/SMSUtil.php';
154
+			$emayClient = new SMSUtil($smsset['emay_url'], $smsset['emay_sn'], $smsset['emay_pw'], $smsset['emay_sk'], array('proxyhost' => $smsset['emay_phost'], 'proxyport' => $smsset['pport'], 'proxyusername' => $smsset['puser'], 'proxypassword' => $smsset['ppw']), $smsset['emay_out'], $smsset['emay_outresp']);
155
+			$num = $emayClient->getBalance();
156
+			if (!empty($smsset['emay_warn']) && !empty($smsset['emay_mobile']) && $num < $smsset['emay_warn'] && $smsset['emay_warn_time'] + 60 * 60 * 24 < time()) {
157
+				$emayClient = new SMSUtil($smsset['emay_url'], $smsset['emay_sn'], $smsset['emay_pw'], $smsset['emay_sk'], array('proxyhost' => $smsset['emay_phost'], 'proxyport' => $smsset['pport'], 'proxyusername' => $smsset['puser'], 'proxypassword' => $smsset['ppw']), $smsset['emay_out'], $smsset['emay_outresp']);
158
+				$emayResult = $emayClient->send($smsset['emay_mobile'], '【系统预警】' . '您的亿美软通SMS余额为:' . $num . ',低于预警值:' . $smsset['emay_warn'] . ' (24小时内仅通知一次)');
159
+
160
+				if (empty($emayResult)) {
161
+					pdo_update('ewei_shop_sms_set', array('emay_warn_time' => time()), array('id' => $smsset['id']));
162
+				}
163
+			}
164
+
165
+			return $num;
166
+		}
167
+	}
168
+
169
+	protected function sms_verify($tplid, $smsset)
170
+	{
171
+		global $_W;
172
+		$template = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_sms') . ' WHERE id=:id and uniacid=:uniacid ', array(':id' => $tplid, ':uniacid' => $_W['uniacid']));
173
+		$template['data'] = iunserializer($template['data']);
174
+
175
+		if (empty($template)) {
176
+			return array('status' => 0, 'message' => '模板不存在!');
177
+		}
178
+
179
+		if (empty($template['status'])) {
180
+			return array('status' => 0, 'message' => '模板未启用!');
181
+		}
182
+
183
+		if (empty($template['type'])) {
184
+			return array('status' => 0, 'message' => '模板类型错误!');
185
+		}
186
+
187
+		if ($template['type'] == 'juhe') {
188
+			if (empty($smsset['juhe'])) {
189
+				return array('status' => 0, 'message' => '未开启聚合数据!');
190
+			}
191
+
192
+			if (empty($smsset['juhe_key'])) {
193
+				return array('status' => 0, 'message' => '未填写聚合数据Key!');
194
+			}
195
+
196
+			if (empty($template['data']) || !is_array($template['data'])) {
197
+				return array('status' => 0, 'message' => '模板类型错误!');
198
+			}
199
+		}
200
+		else if ($template['type'] == 'dayu') {
201
+			if (empty($smsset['dayu'])) {
202
+				return array('status' => 0, 'message' => '未开启阿里大于!');
203
+			}
204
+
205
+			if (empty($smsset['dayu_key'])) {
206
+				return array('status' => 0, 'message' => '未填写阿里大于Key!');
207
+			}
208
+
209
+			if (empty($smsset['dayu_secret'])) {
210
+				return array('status' => 0, 'message' => '未填写阿里大于Secret!');
211
+			}
212
+
213
+			if (empty($template['data']) || !is_array($template['data'])) {
214
+				return array('status' => 0, 'message' => '模板类型错误!');
215
+			}
216
+
217
+			if (empty($template['smssign'])) {
218
+				return array('status' => 0, 'message' => '未填写阿里大于短信签名!');
219
+			}
220
+		}
221
+		else if ($template['type'] == 'aliyun') {
222
+			if (empty($smsset['aliyun'])) {
223
+				return array('status' => 0, 'message' => '未开启阿里云短信(旧版)!');
224
+			}
225
+
226
+			if (empty($smsset['aliyun_appcode'])) {
227
+				return array('status' => 0, 'message' => '未填写阿里云短信AppCode!');
228
+			}
229
+
230
+			if (empty($template['data']) || !is_array($template['data'])) {
231
+				return array('status' => 0, 'message' => '模板类型错误!');
232
+			}
233
+
234
+			if (empty($template['smssign'])) {
235
+				return array('status' => 0, 'message' => '未填写阿里云短信(旧版)签名!');
236
+			}
237
+		}
238
+		else if ($template['type'] == 'aliyun_new') {
239
+			if (empty($smsset['aliyun_new'])) {
240
+				return array('status' => 0, 'message' => '未开启阿里云短信(新版)!');
241
+			}
242
+
243
+			if (empty($smsset['aliyun_new_keyid'])) {
244
+				return array('status' => 0, 'message' => '未填写阿里云短信(新版)KeyID!');
245
+			}
246
+
247
+			if (empty($smsset['aliyun_new_keysecret'])) {
248
+				return array('status' => 0, 'message' => '未填写阿里云短信(新版)keySecret!');
249
+			}
250
+
251
+			if (empty($template['data']) || !is_array($template['data'])) {
252
+				return array('status' => 0, 'message' => '模板类型错误!');
253
+			}
254
+
255
+			if (empty($template['smssign'])) {
256
+				return array('status' => 0, 'message' => '未填写阿里云短信(新版)签名!');
257
+			}
258
+		}
259
+		else {
260
+			if ($template['type'] == 'emay') {
261
+				if (empty($smsset['emay'])) {
262
+					return array('status' => 0, 'message' => '未开启亿美软通!');
263
+				}
264
+
265
+				if (empty($smsset['emay_url'])) {
266
+					return array('status' => 0, 'message' => '未填写亿美软通网关!');
267
+				}
268
+
269
+				if (empty($smsset['emay_sn'])) {
270
+					return array('status' => 0, 'message' => '未填写亿美软通序列号!');
271
+				}
272
+
273
+				if (empty($smsset['emay_pw'])) {
274
+					return array('status' => 0, 'message' => '未填写亿美软通密码!');
275
+				}
276
+
277
+				if (empty($smsset['emay_sk'])) {
278
+					return array('status' => 0, 'message' => '未填写亿美软通SessionKey!');
279
+				}
280
+
281
+				if (empty($template['smssign'])) {
282
+					return array('status' => 0, 'message' => '未填写亿美软通短信签名!');
283
+				}
284
+			}
285
+		}
286
+
287
+		return $template;
288
+	}
289
+
290
+	protected function sms_data($type, $data, $replace, $template)
291
+	{
292
+		if ($replace) {
293
+			if ($type == 'emay') {
294
+				$tempdata = $template['content'];
295
+
296
+				foreach ($data as $key => $value) {
297
+					$tempdata = str_replace('[' . $key . ']', $value, $tempdata);
298
+				}
299
+
300
+				$data = $tempdata;
301
+			}
302
+			else {
303
+				$tempdata = iunserializer($template['data']);
304
+
305
+				foreach ($tempdata as &$td) {
306
+					foreach ($data as $key => $value) {
307
+						$td['data_shop'] = str_replace('[' . $key . ']', $value, $td['data_shop']);
308
+					}
309
+				}
310
+
311
+				unset($td);
312
+				$newdata = array();
313
+
314
+				foreach ($tempdata as $td) {
315
+					$newdata[$td['data_temp']] = $td['data_shop'];
316
+				}
317
+
318
+				$data = $newdata;
319
+			}
320
+		}
321
+
322
+		if ($type == 'juhe') {
323
+			$result = '';
324
+			$count = count($data);
325
+			$i = 0;
326
+
327
+			foreach ($data as $key => $value) {
328
+				if (0 < $i && $i < $count) {
329
+					$result .= '&';
330
+				}
331
+
332
+				$result .= '#' . $key . '#=' . $value;
333
+				++$i;
334
+			}
335
+		}
336
+		else {
337
+			if ($type == 'dayu' || $type == 'aliyun' || $type == 'aliyun_new') {
338
+				$result = json_encode($data);
339
+			}
340
+			else {
341
+				if ($type == 'emay') {
342
+					$result = $data;
343
+				}
344
+			}
345
+		}
346
+
347
+		return $result;
348
+	}
349
+
350
+	protected function http_post($url, $postData)
351
+	{
352
+		$postData = http_build_query($postData);
353
+		$options = array(
354
+			'http' => array('method' => 'POST', 'header' => 'Content-type:application/x-www-form-urlencoded', 'content' => $postData, 'timeout' => 15 * 60)
355
+			);
356
+		$context = stream_context_create($options);
357
+		$result = file_get_contents($url, false, $context);
358
+
359
+		if (!is_array($result)) {
360
+			$result = json_decode($result, true);
361
+		}
362
+
363
+		return $result;
364
+	}
365
+
366
+	protected function http_get($url)
367
+	{
368
+		$result = file_get_contents($url, false);
369
+
370
+		if (!is_array($result)) {
371
+			$result = json_decode($result, true);
372
+		}
373
+
374
+		return $result;
375
+	}
376
+
377
+	public function callsms(array $params)
378
+	{
379
+		global $_W;
380
+		$tag = isset($params['tag']) ? $params['tag'] : '';
381
+		$datas = isset($params['datas']) ? $params['datas'] : array();
382
+		$tm = $_W['shopset']['notice'];
383
+
384
+		if (empty($tm)) {
385
+			$tm = m('common')->getSysset('notice');
386
+		}
387
+
388
+		$smsid = $tm[$tag . '_sms'];
389
+		$smsclose = $tm[$tag . '_close_sms'];
390
+		if (!empty($smsid) && empty($smsclose) && !empty($params['mobile'])) {
391
+			$sms_data = array();
392
+
393
+			foreach ($datas as $i => $value) {
394
+				$sms_data[$value['name']] = $value['value'];
395
+			}
396
+
397
+			$this->send($params['mobile'], $smsid, $sms_data);
398
+		}
399
+	}
400
+}
401
+
402
+?>

+ 16 - 0
addons/ewei_shopv2/core/com/tmessage.php Parādīt failu

@@ -0,0 +1,16 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Tmessage_EweiShopV2ComModel extends ComModel
7
+{
8
+	public function perms()
9
+	{
10
+		return array(
11
+	'tmessage' => array('text' => $this->getName(), 'isplugin' => true, 'view' => '浏览', 'add' => '添加-log', 'edit' => '修改-log', 'delete' => '删除-log', 'send' => '发送-log')
12
+	);
13
+	}
14
+}
15
+
16
+?>

+ 473 - 0
addons/ewei_shopv2/core/com/verify.php Parādīt failu

@@ -0,0 +1,473 @@
1
+<?php  if( !defined("IN_IA") ) 
2
+{
3
+	exit( "Access Denied" );
4
+}
5
+class Verify_EweiShopV2ComModel extends ComModel 
6
+{
7
+	public function createQrcode($orderid = 0) 
8
+	{
9
+		global $_W;
10
+		global $_GPC;
11
+		$path = IA_ROOT . "/addons/ewei_shopv2/data/qrcode/" . $_W["uniacid"];
12
+		if( !is_dir($path) ) 
13
+		{
14
+			load()->func("file");
15
+			mkdirs($path);
16
+		}
17
+		$url = mobileUrl("verify/detai", array( "id" => $orderid ));
18
+		$file = "order_verify_qrcode_" . $orderid . ".png";
19
+		$qrcode_file = $path . "/" . $file;
20
+		if( !is_file($qrcode_file) ) 
21
+		{
22
+			require(IA_ROOT . "/framework/library/qrcode/phpqrcode.php");
23
+			QRcode::png($url, $qrcode_file, QR_ECLEVEL_H, 4);
24
+		}
25
+		return $_W["siteroot"] . "/addons/ewei_shopv2/data/qrcode/" . $_W["uniacid"] . "/" . $file;
26
+	}
27
+	public function allow($orderid, $times = 0, $verifycode = "", $openid = "") 
28
+	{
29
+		global $_W;
30
+		global $_GPC;
31
+		if( empty($openid) ) 
32
+		{
33
+			$openid = $_W["openid"];
34
+		}
35
+		$uniacid = $_W["uniacid"];
36
+		$store = false;
37
+		$merchid = 0;
38
+		$lastverifys = 0;
39
+		$verifyinfo = false;
40
+		if( $times <= 0 ) 
41
+		{
42
+			$times = 1;
43
+		}
44
+		$merch_plugin = p("merch");
45
+		$order = pdo_fetch("select * from " . tablename("ewei_shop_order") . " where id=:id and uniacid=:uniacid  limit 1", array( ":id" => $orderid, ":uniacid" => $uniacid ));
46
+		if( empty($order) ) 
47
+		{
48
+			return error(-1, "订单不存在!");
49
+		}
50
+		if( empty($order["isverify"]) && empty($order["dispatchtype"]) && empty($order["istrade"]) ) 
51
+		{
52
+			return error(-1, "订单无需核销!");
53
+		}
54
+		if( $order["verifyendtime"] < time() && 0 < $order["verifyendtime"] ) 
55
+		{
56
+			return error(-1, "该记录已失效,兑换期限已过!");
57
+		}
58
+		if( $order["paytype"] != 3 && $order["status"] < 1 ) 
59
+		{
60
+			return error(-1, "该订单尚未支付!");
61
+		}
62
+		$merchid = $order["merchid"];
63
+		if( empty($merchid) ) 
64
+		{
65
+			$saler = pdo_fetch("select * from " . tablename("ewei_shop_saler") . " where openid=:openid and uniacid=:uniacid and status=1 limit 1", array( ":uniacid" => $_W["uniacid"], ":openid" => $openid ));
66
+		}
67
+		else 
68
+		{
69
+			if( $merch_plugin ) 
70
+			{
71
+				$saler = pdo_fetch("select * from " . tablename("ewei_shop_merch_saler") . " where openid=:openid and uniacid=:uniacid and status=1 and merchid=:merchid limit 1", array( ":uniacid" => $_W["uniacid"], ":openid" => $openid, ":merchid" => $merchid ));
72
+			}
73
+		}
74
+		if( empty($saler) ) 
75
+		{
76
+			return error(-1, "无核销权限!");
77
+		}
78
+		if( !empty($order["storeid"]) && !empty($saler["storeid"]) && $order["storeid"] != $saler["storeid"] ) 
79
+		{
80
+			return error(1, "该商品无法在您所属门店核销!请重新确认!");
81
+		}
82
+		$newstore_plugin = p("newstore");
83
+		$sqlstr = "";
84
+		if( $newstore_plugin ) 
85
+		{
86
+			$sqlstr .= ",og.trade_time,og.optime,og.peopleid,og.trade_time,og.optime,g.tempid";
87
+		}
88
+		$allgoods = pdo_fetchall("select og.goodsid,og.price,g.title,g.thumb,og.total,g.credit,og.optionid,o.title as optiontitle,g.isverify,g.storeids,g.status" . $sqlstr . " from " . tablename("ewei_shop_order_goods") . " og " . " left join " . tablename("ewei_shop_goods") . " g on g.id=og.goodsid " . " left join " . tablename("ewei_shop_goods_option") . " o on o.id=og.optionid " . " where og.orderid=:orderid and og.uniacid=:uniacid ", array( ":uniacid" => $uniacid, ":orderid" => $orderid ));
89
+		if( empty($allgoods) ) 
90
+		{
91
+			return error(-1, "订单异常!");
92
+		}
93
+		$goods = $allgoods[0];
94
+		if( $order["isverify"] || $order["istrade"] ) 
95
+		{
96
+			if( count($allgoods) != 1 ) 
97
+			{
98
+				$gift = false;
99
+				foreach( $allgoods as $key => $value ) 
100
+				{
101
+					if( $value["status"] == 2 ) 
102
+					{
103
+						$gift = true;
104
+					}
105
+				}
106
+				if( $gift ) 
107
+				{
108
+					return error(-1, "核销单异常!");
109
+				}
110
+			}
111
+			if( 0 < $order["refundid"] && 0 < $order["refundstate"] ) 
112
+			{
113
+				return error(-1, "订单维权中,无法核销!");
114
+			}
115
+			if( $order["status"] == -1 && 0 < $order["refundtime"] ) 
116
+			{
117
+				return error(-1, "订单状态变更,无法核销!");
118
+			}
119
+			$storeids = array( );
120
+			if( !empty($goods["storeids"]) ) 
121
+			{
122
+				$storeids = explode(",", $goods["storeids"]);
123
+			}
124
+			if( !empty($storeids) && !empty($saler["storeid"]) && !in_array($saler["storeid"], $storeids) ) 
125
+			{
126
+				return error(-1, "您无此门店的核销权限!");
127
+			}
128
+			if( $order["verifytype"] == 0 ) 
129
+			{
130
+				if( !empty($order["verified"]) ) 
131
+				{
132
+					return error(-1, "此订单已核销!");
133
+				}
134
+			}
135
+			else 
136
+			{
137
+				if( $order["verifytype"] == 1 ) 
138
+				{
139
+					$verifyinfo = iunserializer($order["verifyinfo"]);
140
+					if( !is_array($verifyinfo) ) 
141
+					{
142
+						$verifyinfo = array( );
143
+					}
144
+					$lastverifys = $goods["total"] - count($verifyinfo);
145
+					if( $lastverifys <= 0 ) 
146
+					{
147
+						return error(-1, "此订单已全部使用!");
148
+					}
149
+					if( $lastverifys < $times ) 
150
+					{
151
+						return error(-1, "最多核销 " . $lastverifys . " 次!");
152
+					}
153
+				}
154
+				else 
155
+				{
156
+					if( $order["verifytype"] == 2 ) 
157
+					{
158
+						$verifyinfo = iunserializer($order["verifyinfo"]);
159
+						$verifys = 0;
160
+						foreach( $verifyinfo as $v ) 
161
+						{
162
+							if( !empty($verifycode) && trim($v["verifycode"]) === trim($verifycode) && $v["verified"] ) 
163
+							{
164
+								return error(-1, "消费码 " . $verifycode . " 已经使用!");
165
+							}
166
+							if( $v["verified"] ) 
167
+							{
168
+								$verifys++;
169
+							}
170
+						}
171
+						$lastverifys = count($verifyinfo) - $verifys;
172
+						if( count($verifyinfo) <= $verifys ) 
173
+						{
174
+							return error(-1, "消费码都已经使用过了!");
175
+						}
176
+					}
177
+					else 
178
+					{
179
+						if( $order["verifytype"] == 3 && !empty($order["verified"]) ) 
180
+						{
181
+							return error(-1, "此订单已核销!");
182
+						}
183
+					}
184
+				}
185
+			}
186
+			if( !empty($saler["storeid"]) ) 
187
+			{
188
+				if( 0 < $merchid ) 
189
+				{
190
+					$store = pdo_fetch("select * from " . tablename("ewei_shop_merch_store") . " where id=:id and uniacid=:uniacid and merchid = :merchid limit 1", array( ":id" => $saler["storeid"], ":uniacid" => $_W["uniacid"], ":merchid" => $merchid ));
191
+				}
192
+				else 
193
+				{
194
+					$store = pdo_fetch("select * from " . tablename("ewei_shop_store") . " where id=:id and uniacid=:uniacid limit 1", array( ":id" => $saler["storeid"], ":uniacid" => $_W["uniacid"] ));
195
+				}
196
+			}
197
+		}
198
+		else 
199
+		{
200
+			if( $order["dispatchtype"] == 1 ) 
201
+			{
202
+				if( 3 <= $order["status"] ) 
203
+				{
204
+					return error(-1, "订单已经完成,无法进行自提!");
205
+				}
206
+				if( 0 < $order["refundid"] && 0 < $order["refundstate"] ) 
207
+				{
208
+					return error(-1, "订单维权中,无法进行自提!");
209
+				}
210
+				if( $order["status"] == -1 && 0 < $order["refundtime"] ) 
211
+				{
212
+					return error(-1, "订单状态变更,无法进行自提!");
213
+				}
214
+				if( !empty($order["storeid"]) ) 
215
+				{
216
+					if( 0 < $merchid ) 
217
+					{
218
+						$store = pdo_fetch("select * from " . tablename("ewei_shop_merch_store") . " where id=:id and uniacid=:uniacid and merchid = :merchid limit 1", array( ":id" => $order["storeid"], ":uniacid" => $_W["uniacid"], ":merchid" => $merchid ));
219
+					}
220
+					else 
221
+					{
222
+						$store = pdo_fetch("select * from " . tablename("ewei_shop_store") . " where id=:id and uniacid=:uniacid limit 1", array( ":id" => $order["storeid"], ":uniacid" => $_W["uniacid"] ));
223
+					}
224
+				}
225
+				if( empty($store) ) 
226
+				{
227
+					return error(-1, "订单未选择自提门店!");
228
+				}
229
+				if( !empty($saler["storeid"]) && $saler["storeid"] != $order["storeid"] ) 
230
+				{
231
+					return error(-1, "您无此门店的自提权限!");
232
+				}
233
+			}
234
+		}
235
+		$carrier = unserialize($order["carrier"]);
236
+		return array( "order" => $order, "store" => $store, "saler" => $saler, "lastverifys" => $lastverifys, "allgoods" => $allgoods, "goods" => $goods, "verifyinfo" => $verifyinfo, "carrier" => $carrier );
237
+	}
238
+	public function verify($orderid = 0, $times = 0, $verifycode = "", $openid = "") 
239
+	{
240
+		global $_W;
241
+		global $_GPC;
242
+		$current_time = time();
243
+		if( empty($openid) ) 
244
+		{
245
+			$openid = $_W["openid"];
246
+		}
247
+		$data = $this->allow($orderid, $times, $verifycode, $openid);
248
+		if( is_error($data) ) 
249
+		{
250
+			return $data;
251
+		}
252
+		extract($data);
253
+		if( $order["isverify"] || $order["istrade"] ) 
254
+		{
255
+			if( $order["verifytype"] == 0 || $order["verifytype"] == 3 ) 
256
+			{
257
+				$change_data = array( "status" => 3, "sendtime" => $current_time, "finishtime" => $current_time, "verifytime" => $current_time, "verified" => 1, "verifyopenid" => $openid, "verifystoreid" => $saler["storeid"] );
258
+				$newstore_plugin = p("newstore");
259
+				if( $newstore_plugin && !empty($order["istrade"]) && $order["tradestatus"] == 1 ) 
260
+				{
261
+					$change_data["tradestatus"] = 2;
262
+					$change_data["tradepaytype"] = 11;
263
+					$change_data["tradepaytime"] = $current_time;
264
+				}
265
+				pdo_update("ewei_shop_order", $change_data, array( "id" => $order["id"] ));
266
+				if( $newstore_plugin && !empty($order["istrade"]) ) 
267
+				{
268
+					$og = $newstore_plugin->getOrderGoods($order["id"]);
269
+					$insert_data = array( );
270
+					$insert_data["uniacid"] = $_W["uniacid"];
271
+					$insert_data["storeid"] = $saler["storeid"];
272
+					$insert_data["goodsid"] = intval($og["goodsid"]);
273
+					$insert_data["orderid"] = $order["id"];
274
+					$insert_data["openid"] = $openid;
275
+					$insert_data["verifytime"] = $current_time;
276
+					$insert_data["verifycode"] = $order["verifycode"];
277
+					$insert_data["verifytype"] = 0;
278
+					$insert_data["merchid"] = 0;
279
+					pdo_insert("ewei_shop_newstore_trade_log", $insert_data);
280
+				}
281
+				$this->finish($openid, $order);
282
+				m("order")->setGiveBalance($orderid, 1);
283
+				m("order")->setStocksAndCredits($orderid, 3);
284
+				m("member")->upgradeLevel($order["openid"], $orderid);
285
+				m("notice")->sendOrderMessage($orderid);
286
+				com_run("printer::sendOrderMessage", $orderid, array( "type" => 0 ));
287
+			}
288
+			else 
289
+			{
290
+				if( $order["verifytype"] == 1 ) 
291
+				{
292
+					$verifyinfo = iunserializer($order["verifyinfo"]);
293
+					for( $i = 1; $i <= $times; $i++ ) 
294
+					{
295
+						$verifyinfo[] = array( "verifyopenid" => $openid, "verifystoreid" => $store["id"], "verifytime" => $current_time );
296
+					}
297
+					pdo_update("ewei_shop_order", array( "verifyinfo" => iserializer($verifyinfo) ), array( "id" => $orderid ));
298
+					com_run("printer::sendOrderMessage", $orderid, array( "type" => 1, "times" => $times, "lastverifys" => $data["lastverifys"] - $times ));
299
+					if( $order["status"] != 3 ) 
300
+					{
301
+						pdo_update("ewei_shop_order", array( "status" => 3, "sendtime" => $current_time, "finishtime" => $current_time ), array( "id" => $order["id"] ));
302
+						$this->finish($openid, $order);
303
+						m("order")->setGiveBalance($orderid, 1);
304
+					}
305
+					m("order")->setStocksAndCredits($orderid, 3);
306
+					m("member")->upgradeLevel($order["openid"], $orderid);
307
+					m("notice")->sendOrderMessage($orderid);
308
+				}
309
+				else 
310
+				{
311
+					if( $order["verifytype"] == 2 ) 
312
+					{
313
+						if( $order["status"] != 3 ) 
314
+						{
315
+							pdo_update("ewei_shop_order", array( "status" => 3, "sendtime" => $current_time, "finishtime" => $current_time, "verifytime" => $current_time, "verified" => 1, "verifyopenid" => $openid, "verifystoreid" => $saler["storeid"] ), array( "id" => $order["id"] ));
316
+							$this->finish($openid, $order);
317
+							m("order")->setGiveBalance($orderid, 1);
318
+						}
319
+						$verifyinfo = iunserializer($order["verifyinfo"]);
320
+						if( !empty($verifycode) ) 
321
+						{
322
+							foreach( $verifyinfo as &$v ) 
323
+							{
324
+								if( !$v["verified"] && trim($v["verifycode"]) === trim($verifycode) ) 
325
+								{
326
+									$v["verifyopenid"] = $openid;
327
+									$v["verifystoreid"] = $store["id"];
328
+									$v["verifytime"] = $current_time;
329
+									$v["verified"] = 1;
330
+								}
331
+							}
332
+							unset($v);
333
+							com_run("printer::sendOrderMessage", $orderid, array( "type" => 2, "verifycode" => $verifycode, "lastverifys" => $data["lastverifys"] - 1 ));
334
+						}
335
+						else 
336
+						{
337
+							$selecteds = array( );
338
+							$printer_code = array( );
339
+							$printer_code_all = array( );
340
+							foreach( $verifyinfo as $v ) 
341
+							{
342
+								if( $v["select"] ) 
343
+								{
344
+									$selecteds[] = $v;
345
+									$printer_code[] = $v["verifycode"];
346
+								}
347
+								$printer_code_all[] = $v["verifycode"];
348
+							}
349
+							if( count($selecteds) <= 0 ) 
350
+							{
351
+								foreach( $verifyinfo as &$v ) 
352
+								{
353
+									$v["verifyopenid"] = $openid;
354
+									$v["verifystoreid"] = $store["id"];
355
+									$v["verifytime"] = $current_time;
356
+									$v["verified"] = 1;
357
+									unset($v["select"]);
358
+								}
359
+								unset($v);
360
+								com_run("printer::sendOrderMessage", $orderid, array( "type" => 2, "verifycode" => implode(",", $printer_code_all), "lastverifys" => 0 ));
361
+							}
362
+							else 
363
+							{
364
+								foreach( $verifyinfo as &$v ) 
365
+								{
366
+									if( $v["select"] ) 
367
+									{
368
+										$v["verifyopenid"] = $openid;
369
+										$v["verifystoreid"] = $store["id"];
370
+										$v["verifytime"] = $current_time;
371
+										$v["verified"] = 1;
372
+										unset($v["select"]);
373
+									}
374
+								}
375
+								unset($v);
376
+								com_run("printer::sendOrderMessage", $orderid, array( "type" => 2, "verifycode" => implode(",", $printer_code), "lastverifys" => $data["lastverifys"] - count($selecteds) ));
377
+							}
378
+						}
379
+						pdo_update("ewei_shop_order", array( "verifyinfo" => iserializer($verifyinfo) ), array( "id" => $order["id"] ));
380
+						m("member")->upgradeLevel($order["openid"], $orderid);
381
+						m("notice")->sendOrderMessage($orderid);
382
+						m("order")->setStocksAndCredits($orderid, 3);
383
+					}
384
+				}
385
+			}
386
+		}
387
+		else 
388
+		{
389
+			if( $order["dispatchtype"] == 1 ) 
390
+			{
391
+				pdo_update("ewei_shop_order", array( "status" => 3, "fetchtime" => $current_time, "sendtime" => $current_time, "finishtime" => $current_time, "verifytime" => $current_time, "verified" => 1, "verifyopenid" => $openid, "verifystoreid" => $saler["storeid"] ), array( "id" => $order["id"] ));
392
+				$this->finish($openid, $order);
393
+				m("order")->setGiveBalance($orderid, 1);
394
+				m("order")->setStocksAndCredits($orderid, 3);
395
+				com_run("printer::sendOrderMessage", $orderid, array( "type" => 0 ));
396
+				m("member")->upgradeLevel($order["openid"], $orderid);
397
+				m("notice")->sendOrderMessage($orderid);
398
+			}
399
+		}
400
+		return true;
401
+	}
402
+	protected function finish($openid, $order) 
403
+	{
404
+		if( p("lottery") ) 
405
+		{
406
+			$res = p("lottery")->getLottery($order["openid"], 1, array( "money" => $order["price"], "paytype" => 2 ));
407
+			if( $res ) 
408
+			{
409
+				p("lottery")->getLotteryList($order["openid"], array( "lottery_id" => $res ));
410
+			}
411
+		}
412
+		m("order")->fullback($order["id"]);
413
+		if( com("coupon") ) 
414
+		{
415
+			$refurnid = com("coupon")->sendcouponsbytask($order["id"]);
416
+		}
417
+		if( p("task") ) 
418
+		{
419
+			p("task")->checkTaskProgress($order["price"], "order_full", "", $openid);
420
+		}
421
+		if( com("coupon") && !empty($order["couponid"]) ) 
422
+		{
423
+			com("coupon")->backConsumeCoupon($order["id"]);
424
+		}
425
+		if( p("commission") ) 
426
+		{
427
+			p("commission")->checkOrderFinish($order["id"]);
428
+		}
429
+	}
430
+	public function perms() 
431
+	{
432
+		return array( "verify" => array( "text" => $this->getName(), "isplugin" => true, "child" => array( "keyword" => array( "text" => "关键词设置-log" ), "store" => array( "text" => "门店", "view" => "浏览", "add" => "添加-log", "edit" => "修改-log", "delete" => "删除-log" ), "saler" => array( "text" => "核销员", "view" => "浏览", "add" => "添加-log", "edit" => "修改-log", "delete" => "删除-log" ) ) ) );
433
+	}
434
+	public function getSalerInfo($openid, $merchid = 0) 
435
+	{
436
+		global $_W;
437
+		$condition = " s.uniacid = :uniacid and s.openid = :openid";
438
+		$params = array( ":uniacid" => $_W["uniacid"], ":openid" => $openid );
439
+		if( empty($merchid) ) 
440
+		{
441
+			$table_name = tablename("ewei_shop_saler");
442
+		}
443
+		else 
444
+		{
445
+			$table_name = tablename("ewei_shop_merch_saler");
446
+			$condition .= " and s.merchid = :merchid";
447
+			$params["merchid"] = $merchid;
448
+		}
449
+		$sql = "SELECT m.id as salerid,m.nickname as salernickname,s.salername FROM " . $table_name . "  s " . " left join " . tablename("ewei_shop_member") . " m on s.openid=m.openid and m.uniacid = s.uniacid " . " WHERE " . $condition . " Limit 1";
450
+		$data = pdo_fetch($sql, $params);
451
+		return $data;
452
+	}
453
+	public function getStoreInfo($storeid, $merchid = 0) 
454
+	{
455
+		global $_W;
456
+		$condition = " uniacid = :uniacid and id = :storeid";
457
+		$params = array( ":uniacid" => $_W["uniacid"], ":storeid" => $storeid );
458
+		if( empty($merchid) ) 
459
+		{
460
+			$table_name = tablename("ewei_shop_store");
461
+		}
462
+		else 
463
+		{
464
+			$table_name = tablename("ewei_shop_merch_store");
465
+			$condition .= " and merchid = :merchid";
466
+			$params["merchid"] = $merchid;
467
+		}
468
+		$sql = "SELECT * FROM " . $table_name . " WHERE " . $condition . " Limit 1";
469
+		$data = pdo_fetch($sql, $params);
470
+		return $data;
471
+	}
472
+}
473
+?>

+ 429 - 0
addons/ewei_shopv2/core/com/virtual.php Parādīt failu

@@ -0,0 +1,429 @@
1
+<?php
2
+
3
+if (!defined('IN_IA')) {
4
+    exit('Access Denied');
5
+}
6
+
7
+class Virtual_EweiShopV2ComModel extends ComModel {
8
+
9
+    public function updateGoodsStock($id = 0) {
10
+
11
+        global $_W, $_GPC;
12
+        $goods = pdo_fetch('select `virtual`,merchid from ' . tablename('ewei_shop_goods') . ' where id=:id and type=3 and uniacid=:uniacid limit 1', array(':id' => $id, ':uniacid' => $_W['uniacid']));
13
+
14
+        if (empty($goods)) {
15
+            return;
16
+        }
17
+        $merchid = $goods['merchid'];
18
+
19
+        $stock = 0;
20
+        //虚拟物品(卡密) 库存
21
+        if (!empty($goods['virtual'])) {
22
+            //单规格
23
+            $stock = pdo_fetchcolumn('select count(*) from ' . tablename('ewei_shop_virtual_data') . " where typeid=:typeid and uniacid=:uniacid and merchid = :merchid and openid='' limit 1", array(':typeid' => $goods['virtual'], ':uniacid' => $_W['uniacid'], ':merchid' => $merchid));
24
+        } else {
25
+            $virtuals = array();
26
+            $alloptions = pdo_fetchall("select id, `virtual` from " . tablename('ewei_shop_goods_option') . " where goodsid=$id");
27
+
28
+            foreach ($alloptions as $opt) {
29
+                if (empty($opt['virtual'])) {
30
+                    continue;
31
+                }
32
+
33
+                $c = pdo_fetchcolumn('select count(*) from ' . tablename('ewei_shop_virtual_data') . " where typeid=:typeid and uniacid=:uniacid and merchid = :merchid and openid='' limit 1", array(':typeid' => $opt['virtual'], ':uniacid' => $_W['uniacid'], ':merchid' => $merchid));
34
+                pdo_update('ewei_shop_goods_option', array('stock' => $c), array('id' => $opt['id']));
35
+                if (!in_array($opt['virtual'], $virtuals)) {
36
+                    $virtuals[] = $opt['virtual'];
37
+                    $stock+=$c;
38
+                }
39
+            }
40
+        }
41
+        pdo_update("ewei_shop_goods", array("total" => $stock), array("id" => $id));
42
+    }
43
+
44
+    public function updateStock($typeid = 0) {
45
+        global $_W;
46
+        $goodsids = array();
47
+
48
+        //先找单规格的
49
+        $goods = pdo_fetchall('select id from ' . tablename('ewei_shop_goods') . ' where `type`=3 and `virtual`=:virtual and uniacid=:uniacid', array(':virtual' => $typeid, ':uniacid' => $_W['uniacid']));
50
+        foreach ($goods as $g) {
51
+            $goodsids[] = $g['id'];
52
+        }
53
+
54
+        //多规格的
55
+        $alloptions = pdo_fetchall("select id, goodsid from " . tablename('ewei_shop_goods_option') . " where `virtual`=:virtual and uniacid=:uniacid", array(':uniacid' => $_W['uniacid'], ':virtual' => $typeid));
56
+        foreach ($alloptions as $opt) {
57
+            if (!in_array($opt['goodsid'], $goodsids)) {
58
+                $goodsids[] = $opt['goodsid'];
59
+            }
60
+        }
61
+        foreach ($goodsids as $gid) {
62
+            $this->updateGoodsStock($gid);
63
+        }
64
+    }
65
+
66
+    //未付款分配虚拟商品
67
+    public function pay_befo($order){
68
+        global $_W, $_GPC;
69
+        $orderid_cache = m("cache")->getString("orderid_".$order['id']);
70
+        if(empty($orderid_cache))
71
+        {
72
+            m("cache")->set("orderid_".$order['id'],1);
73
+        }else
74
+        {
75
+            return false;
76
+        }
77
+
78
+
79
+        $open_redis = function_exists('redis') && !is_error(redis());
80
+
81
+        //虚拟物品直接发货
82
+        $goods = pdo_fetch('select id,goodsid,total,realprice from ' . tablename('ewei_shop_order_goods') . ' where  orderid=:orderid and uniacid=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':orderid' => $order['id']));
83
+        $g = pdo_fetch('select id,credit,sales,salesreal from ' . tablename('ewei_shop_goods') . ' where  id=:id and uniacid=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':id' => $goods['goodsid']));
84
+
85
+        //如果redis可用,则取最后一个使用过的卡密id 拼接 sql
86
+        $last_where='';
87
+        if($open_redis) {
88
+            $redis=redis();
89
+            $last_id = $redis->get($_W['uniacid'].'_last_virtual_id_'.$order['virtual'].'_'.$order['merchid']);
90
+            $last_used = pdo_fetch('select id,typeid,is_top,sort_time from ' . tablename('ewei_shop_virtual_data') . ' where  id=:id and uniacid=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':id' => $last_id));
91
+            //如果上一条不是被置顶的卡密数据 , 则下一条ID+1
92
+            if (!empty($last_id) && !empty($last_used) && $last_used['is_top'] == 0) {
93
+                $last_id=intval($last_id);
94
+                $last_where=" and id>".$last_id;
95
+            }
96
+        }
97
+
98
+        $sort_order = 'orderid ASC,is_top desc,sort_time desc,id ASC';
99
+        $virtual_data = pdo_fetchall('SELECT id,typeid,fields FROM ' . tablename('ewei_shop_virtual_data') . ' WHERE typeid=:typeid and orderid=:orderid and uniacid=:uniacid and merchid = :merchid '.$last_where.' order by '.$sort_order.' limit ' . $goods['total'], array(':orderid' => 0, ':typeid' => $order['virtual'], ':uniacid' => $_W['uniacid'], ':merchid' => $order['merchid']));
100
+        if(count($virtual_data) < $goods['total']){
101
+            return array('error'=>-1,'message'=>'库存不足');
102
+        }
103
+
104
+        //将最后一个将要使用的卡密id存到redis
105
+        if(!empty($virtual_data)){
106
+            $last_virtual_id = max(array_column($virtual_data, 'id'));
107
+            if($open_redis && !empty($last_virtual_id)) {
108
+                $redis=redis();
109
+                $redis->set($_W['uniacid'].'_last_virtual_id_'.$order['virtual'].'_'.$order['merchid'], $last_virtual_id, 30);
110
+            }
111
+        }
112
+
113
+        $type = pdo_fetch('select fields from ' . tablename('ewei_shop_virtual_type') . ' where id=:id and uniacid=:uniacid and merchid = :merchid limit 1 ', array(':id' => $order['virtual'], ':uniacid' => $_W['uniacid'], ':merchid' => $order['merchid']));
114
+        $fields = iunserializer($type['fields'], true);
115
+        $virtual_info = array();
116
+        $virtual_str = array();
117
+        foreach ($virtual_data as $vd) {
118
+
119
+            //数据
120
+            $virtual_info[] = $vd['fields'];
121
+
122
+            //显示
123
+            $strs = array();
124
+            $vddatas = iunserializer($vd['fields']);
125
+
126
+            foreach ($vddatas as $vk => $vv) {
127
+                $strs[] = $fields[$vk] . ": " . $vv;
128
+            }
129
+            $virtual_str[] = implode(" ", $strs);
130
+
131
+            //更新虚拟物品数据
132
+            pdo_update('ewei_shop_virtual_data', array(
133
+                'openid' => $order['openid'],
134
+                'orderid' => $order['id'],
135
+                'ordersn' => $order['ordersn'],
136
+                'price' => round($goods['realprice'] / $goods['total'], 2),
137
+                'usetime' => time()
138
+            ), array('id' => $vd['id']));
139
+            pdo_update('ewei_shop_virtual_type', 'usedata=usedata+1', array('id' => $vd['typeid']));
140
+            //更新库存
141
+//            $this->updateStock($vd['typeid']); //弃用(解决一次购买N件商品时卡顿的问题) SuniW-2018.7.23
142
+        }
143
+        //更新库存
144
+        $this->updateStock($order['virtual']);
145
+        $virtual_str = implode("\n", $virtual_str);
146
+        $virtual_info = "[" . implode(",", $virtual_info) . "]";
147
+
148
+        //更新订单的状态
149
+        $time = time();
150
+        pdo_update('ewei_shop_order', array('virtual_info' => $virtual_info, 'virtual_str' => $virtual_str, 'sendtime' => $time), array('id' => $order['id']));
151
+
152
+        //将卡密内容存到redis里面
153
+        if($open_redis && !empty($virtual_str)) {
154
+            $redis=redis();
155
+            $redis->set($order['id'] . '_virtual_str', $virtual_str, 30);
156
+        }
157
+        return true;
158
+    }
159
+
160
+    public function pay($order,$ispeerpay=false) {
161
+        global $_W, $_GPC;
162
+
163
+
164
+        //虚拟物品直接发货
165
+        $goods = pdo_fetch('select id,goodsid,total,realprice from ' . tablename('ewei_shop_order_goods') . ' where  orderid=:orderid and uniacid=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':orderid' => $order['id']));
166
+        $g = pdo_fetch('select id,credit,sales,salesreal from ' . tablename('ewei_shop_goods') . ' where  id=:id and uniacid=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':id' => $goods['goodsid']));
167
+        $virtual_data = pdo_fetchall('SELECT id,typeid,fields FROM ' . tablename('ewei_shop_virtual_data') . ' WHERE typeid=:typeid and openid=:openid and uniacid=:uniacid and merchid = :merchid order by id asc limit ' . $goods['total'], array(':openid' => '', ':typeid' => $order['virtual'], ':uniacid' => $_W['uniacid'], ':merchid' => $order['merchid']));
168
+        $type = pdo_fetch('select fields from ' . tablename('ewei_shop_virtual_type') . ' where id=:id and uniacid=:uniacid and merchid = :merchid limit 1 ', array(':id' => $order['virtual'], ':uniacid' => $_W['uniacid'], ':merchid' => $order['merchid']));
169
+
170
+
171
+        //更新订单的状态
172
+        $time = time();
173
+        pdo_update('ewei_shop_order', array('status' => '3', 'paytime' => $time, 'sendtime' => $time, 'finishtime' => $time), array('id' => $order['id']));
174
+
175
+        //处理余额抵扣
176
+        /*if ($order['deductcredit2'] > 0) {
177
+            $shopset = m('common')->getSysset('shop');
178
+            m('member')->setCredit($order['openid'], 'credit2', -$order['deductcredit2'], array(0, $shopset['name'] . "余额抵扣: {$order['deductcredit2']} 订单号: " . $order['ordersn']));
179
+        }*/
180
+
181
+        //购物积分
182
+        //$credits = $goods['total'] * $g['credit'];
183
+        $credits = 0;
184
+        $gcredit = trim($g['credit']);
185
+        if (!empty($gcredit)) {
186
+            if (strexists($gcredit, '%')) {
187
+                //按比例计算
188
+                $credits += intval(floatval(str_replace('%', '', $gcredit)) / 100 * $goods['realprice']);
189
+            } else {
190
+                //按固定值计算
191
+                $credits += intval($g['credit']) * $goods['total'];
192
+            }
193
+        }
194
+        if ($credits > 0) {
195
+            $shopset = m('common')->getSysset('shop');
196
+            m('member')->setCredit($order['openid'], 'credit1', $credits, array(0, $shopset['name'] . '购物积分 订单号: ' . $order['ordersn']));
197
+        }else{
198
+                //积分活动订单送积分
199
+                $money = com_run('sale::getCredit1', $order['openid'], (float)$order['price'], $order['paytype'], 1);
200
+                if ($money > 0) {
201
+                    m('notice')->sendMemberPointChange($order['openid'], $money, 0,3);
202
+                }
203
+            }
204
+            
205
+        //实际销量
206
+        $salesreal = pdo_fetchcolumn('select ifnull(sum(total),0) from ' . tablename('ewei_shop_order_goods') . ' og '
207
+            . ' left join ' . tablename('ewei_shop_order') . ' o on o.id = og.orderid '
208
+            . ' where og.goodsid=:goodsid and o.status>=1 and o.uniacid=:uniacid limit 1', array(':goodsid' => $g['id'], ':uniacid' => $_W['uniacid']));
209
+        pdo_update('ewei_shop_goods', array('salesreal' => $salesreal), array('id' => $g['id']));
210
+
211
+        //商品全返
212
+        m('order')->fullback($order['id']);
213
+        //会员升级
214
+        m('member')->upgradeLevel($order['openid'], $order['id']);
215
+
216
+        //模板消息
217
+        m('notice')->sendOrderMessage($order['id']);
218
+
219
+        //余额赠送
220
+        m('order')->setGiveBalance($order['id'], 1);
221
+
222
+        //小票打印
223
+        com_run('printer::sendOrderMessage', $order['id']);
224
+
225
+        //发送赠送优惠券
226
+        if (com('coupon')) {
227
+            com('coupon')->sendcouponsbytask($order['id']); //订单支付
228
+        }
229
+
230
+        //优惠券返利
231
+        if (com('coupon') && !empty($order['couponid'])) {
232
+            com('coupon')->backConsumeCoupon($order['id']); //虚拟物品支付
233
+        }
234
+
235
+        //分销
236
+        if (p('commission')) {
237
+            //付款后
238
+            p('commission')->checkOrderPay($order['id']);
239
+
240
+            //收货后
241
+            p('commission')->checkOrderFinish($order['id']);
242
+        }
243
+
244
+        if (p('task')){
245
+
246
+            //余额抵扣加入金额计算
247
+            if($order['deductcredit2'] > 0 ){
248
+                $order['price'] = floatval($order['price']) + floatval($order['deductcredit2']);
249
+            }
250
+            //积分抵扣加入金额计算
251
+            if($order['deductcredit'] > 0){
252
+                $order['price'] = floatval($order['price']) + floatval($order['deductprice']);
253
+            }
254
+
255
+            if ($order['agentid']){
256
+                p('task')->checkTaskReward('commission_order',1);//分销订单
257
+            }
258
+            p('task')->checkTaskReward('cost_total',$order['price']);
259
+            p('task')->checkTaskReward('cost_enough',$order['price']);
260
+            p('task')->checkTaskReward('cost_count',1);
261
+            $goodslist = pdo_fetchall("SELECT goodsid FROM ".tablename('ewei_shop_order_goods')." WHERE orderid = :orderid AND uniacid = :uniacid",array(':orderid'=>$order['id'], ':uniacid'=>$order['uniacid']));
262
+            foreach($goodslist as $item) {
263
+                p('task')->checkTaskReward('cost_goods'.$item['goodsid'],1,$order['openid']);
264
+            }
265
+
266
+            //余额抵扣加入金额计算
267
+            if($order['deductcredit2'] > 0 ){
268
+                $order['price'] = floatval($order['price']) + floatval($order['deductcredit2']);
269
+            }
270
+            //积分抵扣加入金额计算
271
+            if($order['deductcredit'] > 0){
272
+                $order['price'] = floatval($order['price']) + floatval($order['deductprice']);
273
+            }
274
+
275
+            //订单满额
276
+            p('task')->checkTaskProgress($order['price'],'order_full');
277
+            p('task')->checkTaskProgress($order['price'],'order_all');
278
+            //购买指定商品
279
+            $goodslist = pdo_fetchall("SELECT goodsid FROM ".tablename('ewei_shop_order_goods')." WHERE orderid = :orderid AND uniacid = :uniacid",array(':orderid'=>$order['id'], ':uniacid'=>$order['uniacid']));
280
+            foreach($goodslist as $item) {
281
+                p('task')->checkTaskProgress(1,'goods',0,'',$item['goodsid']);
282
+            }
283
+            //首次购物
284
+            if (pdo_fetchcolumn("select count(*) from ".tablename('ewei_shop_order')." where openid = '{$order['openid']}' and uniacid = {$order['uniacid']}")==1){
285
+                p('task')->checkTaskProgress(1,'order_first');
286
+            }
287
+        }
288
+
289
+        //抽奖模块
290
+        if(p('lottery')&&empty($ispeerpay)){
291
+            //余额抵扣加入金额计算
292
+            if($order['deductcredit2'] > 0 ){
293
+                $order['price'] = floatval($order['price']) + floatval($order['deductcredit2']);
294
+            }
295
+            //积分抵扣加入金额计算
296
+            if($order['deductcredit'] > 0){
297
+                $order['price'] = floatval($order['price']) + floatval($order['deductprice']);
298
+            }
299
+
300
+            //type 1:消费 2:签到 3:任务 4:其他
301
+            $res = p('lottery')->getLottery($order['openid'],1,array('money'=>$order['price'],'paytype'=>1));
302
+
303
+            if($res){
304
+                //发送模版消息
305
+                p('lottery')->getLotteryList($order['openid'],array('lottery_id'=>$res));
306
+            }
307
+        }
308
+
309
+        return true;
310
+    }
311
+
312
+
313
+//    public function pay($order) {
314
+//
315
+//        global $_W, $_GPC;
316
+//
317
+//        $orderid_cache = m("cache")->getString("orderid_".$order['id']);
318
+//        if(empty($orderid_cache))
319
+//        {
320
+//            m("cache")->set("orderid_".$order['id'],1);
321
+//        }else
322
+//        {
323
+//            return false;
324
+//        }
325
+//        //虚拟物品直接发货
326
+//        $goods = pdo_fetch('select id,goodsid,total,realprice from ' . tablename('ewei_shop_order_goods') . ' where  orderid=:orderid and uniacid=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':orderid' => $order['id']));
327
+//        $g = pdo_fetch('select id,credit,sales,salesreal from ' . tablename('ewei_shop_goods') . ' where  id=:id and uniacid=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':id' => $goods['goodsid']));
328
+//        $virtual_data = pdo_fetchall('SELECT id,typeid,fields FROM ' . tablename('ewei_shop_virtual_data') . ' WHERE typeid=:typeid and openid=:openid and uniacid=:uniacid and merchid = :merchid order by id asc limit ' . $goods['total'], array(':openid' => '', ':typeid' => $order['virtual'], ':uniacid' => $_W['uniacid'], ':merchid' => $order['merchid']));
329
+//        $type = pdo_fetch('select fields from ' . tablename('ewei_shop_virtual_type') . ' where id=:id and uniacid=:uniacid and merchid = :merchid limit 1 ', array(':id' => $order['virtual'], ':uniacid' => $_W['uniacid'], ':merchid' => $order['merchid']));
330
+//        $fields = iunserializer($type['fields'], true);
331
+//        $virtual_info = array();
332
+//        $virtual_str = array();
333
+//        foreach ($virtual_data as $vd) {
334
+//
335
+//            //数据
336
+//            $virtual_info[] = $vd['fields'];
337
+//
338
+//            //显示
339
+//            $strs = array();
340
+//            $vddatas = iunserializer($vd['fields']);
341
+//
342
+//            foreach ($vddatas as $vk => $vv) {
343
+//                $strs[] = $fields[$vk] . ": " . $vv;
344
+//            }
345
+//            $virtual_str[] = implode(" ", $strs);
346
+//
347
+//            //更新虚拟物品数据
348
+//            pdo_update('ewei_shop_virtual_data', array(
349
+//                'openid' => $order['openid'],
350
+//                'orderid' => $order['id'],
351
+//                'ordersn' => $order['ordersn'],
352
+//                'price' => round($goods['realprice'] / $goods['total'], 2),
353
+//                'usetime' => time()
354
+//            ), array('id' => $vd['id']));
355
+//            pdo_update('ewei_shop_virtual_type', 'usedata=usedata+1', array('id' => $vd['typeid']));
356
+//            //更新库存
357
+//            $this->updateStock($vd['typeid']);
358
+//        }
359
+//        $virtual_str = implode("\n", $virtual_str);
360
+//        $virtual_info = "[" . implode(",", $virtual_info) . "]";
361
+//
362
+//        //更新订单的状态
363
+//        $time = time();
364
+//        pdo_update('ewei_shop_order', array('virtual_info' => $virtual_info, 'virtual_str' => $virtual_str, 'status' => '3', 'paytime' => $time, 'sendtime' => $time, 'finishtime' => $time), array('id' => $order['id']));
365
+//
366
+//        //处理余额抵扣
367
+//        /*if ($order['deductcredit2'] > 0) {
368
+//            $shopset = m('common')->getSysset('shop');
369
+//            m('member')->setCredit($order['openid'], 'credit2', -$order['deductcredit2'], array(0, $shopset['name'] . "余额抵扣: {$order['deductcredit2']} 订单号: " . $order['ordersn']));
370
+//        }*/
371
+//
372
+//        //购物积分
373
+//        //$credits = $goods['total'] * $g['credit'];
374
+//        $credits = 0;
375
+//        $gcredit = trim($g['credit']);
376
+//        if (!empty($gcredit)) {
377
+//            if (strexists($gcredit, '%')) {
378
+//                //按比例计算
379
+//                $credits += intval(floatval(str_replace('%', '', $gcredit)) / 100 * $goods['realprice']);
380
+//            } else {
381
+//                //按固定值计算
382
+//                $credits += intval($g['credit']) * $goods['total'];
383
+//            }
384
+//        }
385
+//        if ($credits > 0) {
386
+//            $shopset = m('common')->getSysset('shop');
387
+//            m('member')->setCredit($order['openid'], 'credit1', $credits, array(0, $shopset['name'] . '购物积分 订单号: ' . $order['ordersn']));
388
+//        }
389
+//
390
+//        //实际销量
391
+//        $salesreal = pdo_fetchcolumn('select ifnull(sum(total),0) from ' . tablename('ewei_shop_order_goods') . ' og '
392
+//            . ' left join ' . tablename('ewei_shop_order') . ' o on o.id = og.orderid '
393
+//            . ' where og.goodsid=:goodsid and o.status>=1 and o.uniacid=:uniacid limit 1', array(':goodsid' => $g['id'], ':uniacid' => $_W['uniacid']));
394
+//        pdo_update('ewei_shop_goods', array('salesreal' => $salesreal), array('id' => $g['id']));
395
+//
396
+//        //商品全返
397
+//        m('order')->fullback($order['id']);
398
+//        //会员升级
399
+//        m('member')->upgradeLevel($order['openid'], $order['id']);
400
+//
401
+//        //模板消息
402
+//        m('notice')->sendOrderMessage($order['id']);
403
+//
404
+//        //余额赠送
405
+//        m('order')->setGiveBalance($order['id'], 1);
406
+//
407
+//        //发送赠送优惠券
408
+//        if (com('coupon')) {
409
+//            com('coupon')->sendcouponsbytask($order['id']); //订单支付
410
+//        }
411
+//
412
+//        //优惠券返利
413
+//        if (com('coupon') && !empty($order['couponid'])) {
414
+//            com('coupon')->backConsumeCoupon($order['id']); //虚拟物品支付
415
+//        }
416
+//
417
+//        //分销
418
+//        if (p('commission')) {
419
+//            //付款后
420
+//            p('commission')->checkOrderPay($order['id']);
421
+//
422
+//            //收货后
423
+//            p('commission')->checkOrderFinish($order['id']);
424
+//        }
425
+//
426
+//        return true;
427
+//    }
428
+
429
+}

+ 14 - 0
addons/ewei_shopv2/core/com/wap.php Parādīt failu

@@ -0,0 +1,14 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Wap_EweiShopV2ComModel extends ComModel
7
+{
8
+	public function getSet()
9
+	{
10
+		return '';
11
+	}
12
+}
13
+
14
+?>

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1840 - 0
addons/ewei_shopv2/core/com/wxcard.php


+ 9 - 0
addons/ewei_shopv2/core/inc/com_model.php Parādīt failu

@@ -0,0 +1,9 @@
1
+<?php
2
+class ComModel
3
+{}
4
+
5
+if (!defined('IN_IA')) {
6
+	exit('Access Denied');
7
+}
8
+
9
+?>

+ 33 - 0
addons/ewei_shopv2/core/inc/com_processor.php Parādīt failu

@@ -0,0 +1,33 @@
1
+<?php
2
+if (!(defined('IN_IA'))) 
3
+{
4
+	exit('Access Denied');
5
+}
6
+require dirname(__DIR__) . '/../defines.php';
7
+class ComProcessor extends WeModuleProcessor 
8
+{
9
+	public $model;
10
+	public $modulename;
11
+	public $message;
12
+	public function __construct($name = '') 
13
+	{
14
+		$this->modulename = 'ewei_shopv2';
15
+		$this->pluginname = $name;
16
+		$this->loadModel();
17
+	}
18
+	private function loadModel() 
19
+	{
20
+		$modelfile = IA_ROOT . '/addons/' . $this->modulename . '/core/com/' . $this->pluginname . '.php';
21
+		if (is_file($modelfile)) 
22
+		{
23
+			$classname = ucfirst($this->pluginname) . '_EweiShopV2ComModel';
24
+			require $modelfile;
25
+			$this->model = new $classname($this->pluginname);
26
+		}
27
+	}
28
+	public function respond() 
29
+	{
30
+		$this->message = $this->message;
31
+	}
32
+}
33
+?>

+ 23 - 0
addons/ewei_shopv2/core/inc/data_model.php Parādīt failu

@@ -0,0 +1,23 @@
1
+<?php
2
+class DataModel
3
+{
4
+	public function read($key = '')
5
+	{
6
+		global $_W;
7
+		global $_GPC;
8
+		return m('cache')->getArray('data_' . $_W['uniacid'] . '_' . $key);
9
+	}
10
+
11
+	public function write($key, $data)
12
+	{
13
+		global $_W;
14
+		global $_GPC;
15
+		m('cache')->set('data_' . $_W['uniacid'] . '_' . $key, $data);
16
+	}
17
+}
18
+
19
+if (!defined('IN_IA')) {
20
+	exit('Access Denied');
21
+}
22
+
23
+?>

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3203 - 0
addons/ewei_shopv2/core/inc/functions.php


+ 524 - 0
addons/ewei_shopv2/core/inc/page.php Parādīt failu

@@ -0,0 +1,524 @@
1
+<?php  if( !defined("IN_IA") ) 
2
+{
3
+	exit( "Access Denied" );
4
+}
5
+class Page extends WeModuleSite 
6
+{
7
+	public function runTasks() 
8
+	{
9
+		global $_W;
10
+		load()->func("communication");
11
+		$lasttime = strtotime(m("cache")->getString("receive", "global"));
12
+		$interval = intval(m("cache")->getString("receive_time", "global"));
13
+		if( empty($interval) ) 
14
+		{
15
+			$interval = 60;
16
+		}
17
+		$interval *= 60;
18
+		$current = time();
19
+		if( $lasttime + $interval <= $current ) 
20
+		{
21
+			m("cache")->set("receive", date("Y-m-d H:i:s", $current), "global");
22
+			ihttp_request(EWEI_SHOPV2_TASK_URL . "order/receive.php", NULL, NULL, 1);
23
+		}
24
+		$lasttime = strtotime(m("cache")->getString("closeorder", "global"));
25
+		$interval = intval(m("cache")->getString("closeorder_time", "global"));
26
+		if( empty($interval) ) 
27
+		{
28
+			$interval = 60;
29
+		}
30
+		$interval *= 60;
31
+		$current = time();
32
+		if( $lasttime + $interval <= $current ) 
33
+		{
34
+			m("cache")->set("closeorder", date("Y-m-d H:i:s", $current), "global");
35
+			ihttp_request(EWEI_SHOPV2_TASK_URL . "order/close.php", NULL, NULL, 1);
36
+		}
37
+		$lasttime = strtotime(m("cache")->getString("closeorder_virtual", "global"));
38
+		$interval_v = intval(m("cache")->getString("closeorder_virtual_time", "global"));
39
+		if( empty($interval_v) ) 
40
+		{
41
+			$interval_v = 60;
42
+		}
43
+		$current = time();
44
+		if( $lasttime + $interval_v <= $current ) 
45
+		{
46
+			m("cache")->set("closeorder_virtual", date("Y-m-d H:i:s", $current), "global");
47
+			ihttp_request(EWEI_SHOPV2_TASK_URL . "order/close.php", array( "uniacid" => $_W["uniacid"] ), NULL, 1);
48
+		}
49
+		$lasttime = strtotime(m("cache")->getString("fullback_receive", "global"));
50
+		$interval = intval(m("cache")->getString("fullback_receive_time", "global"));
51
+		if( empty($interval) ) 
52
+		{
53
+			$interval = 60;
54
+		}
55
+		$interval *= 60;
56
+		$current = time();
57
+		if( $lasttime + $interval <= $current ) 
58
+		{
59
+			m("cache")->set("fullback_receive", date("Y-m-d H:i:s", $current), "global");
60
+			ihttp_request(EWEI_SHOPV2_TASK_URL . "order/fullback.php", NULL, NULL, 1);
61
+		}
62
+		$lasttime = strtotime(m("cache")->getString("presell_status", "global"));
63
+		$interval = intval(m("cache")->getString("presell_status_time", "global"));
64
+		if( empty($interval) ) 
65
+		{
66
+			$interval = 60;
67
+		}
68
+		$interval *= 60;
69
+		$current = time();
70
+		if( $lasttime + $interval <= $current ) 
71
+		{
72
+			m("cache")->set("presell_status", date("Y-m-d H:i:s", $current), "global");
73
+			ihttp_request(EWEI_SHOPV2_TASK_URL . "goods/presell.php", NULL, NULL, 1);
74
+		}
75
+		$lasttime = strtotime(m("cache")->getString("status_receive", "global"));
76
+		$interval = intval(m("cache")->getString("status_receive_time", "global"));
77
+		if( empty($interval) ) 
78
+		{
79
+			$interval = 60;
80
+		}
81
+		$interval *= 60;
82
+		$current = time();
83
+		if( $lasttime + $interval <= $current ) 
84
+		{
85
+			m("cache")->set("status_receive", date("Y-m-d H:i:s", $current), "global");
86
+			ihttp_request(EWEI_SHOPV2_TASK_URL . "goods/status.php", NULL, NULL, 1);
87
+		}
88
+		if( com("coupon") ) 
89
+		{
90
+			$lasttime = strtotime(m("cache")->getString("willcloseorder", "global"));
91
+			$interval = intval(m("cache")->getString("willcloseorder_time", "global"));
92
+			if( empty($interval) ) 
93
+			{
94
+				$interval = 20;
95
+			}
96
+			$interval *= 60;
97
+			$current = time();
98
+			if( $lasttime + $interval <= $current ) 
99
+			{
100
+				m("cache")->set("willcloseorder", date("Y-m-d H:i:s", $current), "global");
101
+				ihttp_request(EWEI_SHOPV2_TASK_URL . "order/willclose.php", NULL, NULL, 1);
102
+			}
103
+		}
104
+		if( com("coupon") ) 
105
+		{
106
+			$lasttime = strtotime(m("cache")->getString("couponback", "global"));
107
+			$interval = intval(m("cache")->getString("couponback_time", "global"));
108
+			if( empty($interval) ) 
109
+			{
110
+				$interval = 60;
111
+			}
112
+			$interval *= 60;
113
+			$current = time();
114
+			if( $lasttime + $interval <= $current ) 
115
+			{
116
+				m("cache")->set("couponback", date("Y-m-d H:i:s", $current), "global");
117
+				ihttp_request(EWEI_SHOPV2_TASK_URL . "coupon/back.php", NULL, NULL, 1);
118
+			}
119
+		}
120
+		$lasttime = strtotime(m("cache")->getString("sendnotice", "global"));
121
+		$interval = intval(m("cache")->getString("sendnotice_time", "global"));
122
+		if( empty($interval) ) 
123
+		{
124
+			$interval = 60;
125
+		}
126
+		$interval *= 60;
127
+		$current = time();
128
+		if( $lasttime + $interval <= $current ) 
129
+		{
130
+			m("cache")->set("sendnotice", date("Y-m-d H:i:s", $current), "global");
131
+			ihttp_request(EWEI_SHOPV2_TASK_URL . "notice/sendnotice.php", array( "uniacid" => $_W["uniacid"] ), NULL, 1);
132
+		}
133
+		$lasttime = strtotime(m("cache")->getString("sendcycelbuy", "global"));
134
+		$interval = intval(m("cache")->getString("sendcycelbuy_time", "global"));
135
+		if( empty($interval) ) 
136
+		{
137
+			$interval = 60;
138
+		}
139
+		$interval *= 60;
140
+		$current = time();
141
+		if( $lasttime + $interval <= $current ) 
142
+		{
143
+			m("cache")->set("sendcycelbuy", date("Y-m-d H:i:s", $current), "global");
144
+			ihttp_request(EWEI_SHOPV2_TASK_URL . "cycelbuy/sendnotice.php", array( "uniacid" => $_W["uniacid"] ), NULL, 1);
145
+		}
146
+		$lasttime = strtotime(m("cache")->getString("cycelbuyreceive", "global"));
147
+		$interval = intval(m("cache")->getString("cycelbuyreceive_time", "global"));
148
+		if( empty($interval) ) 
149
+		{
150
+			$interval = 60;
151
+		}
152
+		$interval *= 60;
153
+		$current = time();
154
+		if( $lasttime + $interval <= $current ) 
155
+		{
156
+			m("cache")->set("cycelbuyreceive", date("Y-m-d H:i:s", $current), "global");
157
+			ihttp_request(EWEI_SHOPV2_TASK_URL . "cycelbuy/receive.php", array( "uniacid" => $_W["uniacid"] ), NULL, 1);
158
+		}
159
+		if( p("groups") ) 
160
+		{
161
+			$groups_order_lasttime = strtotime(m("cache")->getString("groups_order_cancelorder", "global"));
162
+			$groups_order_interval = intval(m("cache")->getString("groups_order_cancelorder_time", "global"));
163
+			if( empty($groups_order_interval) ) 
164
+			{
165
+				$groups_order_interval = 60;
166
+			}
167
+			$groups_order_interval *= 60;
168
+			$groups_order_current = time();
169
+			if( $groups_order_lasttime + $groups_order_interval <= $groups_order_current ) 
170
+			{
171
+				m("cache")->set("groups_order_cancelorder", date("Y-m-d H:i:s", $groups_order_current), "global");
172
+				ihttp_request($_W["siteroot"] . "addons/ewei_shopv2/plugin/groups/task/order.php", NULL, NULL, 1);
173
+			}
174
+			$groups_team_lasttime = strtotime(m("cache")->getString("groups_team_refund", "global"));
175
+			$groups_team_interval = intval(m("cache")->getString("groups_team_refund_time", "global"));
176
+			if( empty($groups_team_interval) ) 
177
+			{
178
+				$groups_team_interval = 60;
179
+			}
180
+			$groups_team_interval *= 60;
181
+			$groups_team_current = time();
182
+			if( $groups_team_lasttime + $groups_team_interval <= $groups_team_current ) 
183
+			{
184
+				m("cache")->set("groups_team_refund", date("Y-m-d H:i:s", $groups_team_current), "global");
185
+				ihttp_request($_W["siteroot"] . "addons/ewei_shopv2/plugin/groups/task/refund.php", NULL, NULL, 1);
186
+			}
187
+			$groups_receive_lasttime = strtotime(m("cache")->getString("groups_receive", "global"));
188
+			$groups_receive_interval = intval(m("cache")->getString("groups_receive_time", "global"));
189
+			if( empty($groups_receive_interval) ) 
190
+			{
191
+				$groups_receive_interval = 60;
192
+			}
193
+			$groups_receive_interval *= 60;
194
+			$groups_receive_current = time();
195
+			if( $groups_receive_lasttime + $groups_receive_interval <= $groups_receive_current ) 
196
+			{
197
+				m("cache")->set("groups_receive", date("Y-m-d H:i:s", $groups_receive_current), "global");
198
+				ihttp_request($_W["siteroot"] . "addons/ewei_shopv2/plugin/groups/task/receive.php", NULL, NULL, 1);
199
+			}
200
+		}
201
+		if( p("seckill") ) 
202
+		{
203
+			$lasttime = strtotime(m("cache")->getString("seckill_delete_lasttime", "global"));
204
+			$interval = 5 * 60;
205
+			$current = time();
206
+			if( $lasttime + $interval <= $current ) 
207
+			{
208
+				m("cache")->set("seckill_delete_lasttime", date("Y-m-d H:i:s", $current), "global");
209
+				ihttp_request($_W["siteroot"] . "addons/ewei_shopv2/plugin/seckill/task/delete.php", NULL, NULL, 1);
210
+			}
211
+		}
212
+	}
213
+	public function template($filename = "", $type = TEMPLATE_INCLUDEPATH, $account = false) 
214
+	{
215
+		global $_W;
216
+		global $_GPC;
217
+		$isv3 = true;
218
+		if( isset($_W["shopversion"]) ) 
219
+		{
220
+			$isv3 = $_W["shopversion"];
221
+		}
222
+		if( $isv3 && !empty($_GPC["v2"]) ) 
223
+		{
224
+			$isv3 = false;
225
+		}
226
+		if( !empty($_W["plugin"]) && $isv3 ) 
227
+		{
228
+			$plugin_config = m("plugin")->getConfig($_W["plugin"]);
229
+			if( is_array($plugin_config) && empty($plugin_config["v3"]) || !$plugin_config ) 
230
+			{
231
+				$isv3 = false;
232
+			}
233
+		}
234
+		$bsaeTemp = array( "_header", "_header_base", "_footer", "_tabs", "funbar" );
235
+		if( $_W["plugin"] == "merch" && $_W["merch_user"] && (!in_array($filename, $bsaeTemp) || !$isv3) ) 
236
+		{
237
+			return $this->template_merch($filename, $isv3);
238
+		}
239
+		if( empty($filename) ) 
240
+		{
241
+			$filename = str_replace(".", "/", $_W["routes"]);
242
+		}
243
+		if( $_GPC["do"] == "web" || defined("IN_SYS") ) 
244
+		{
245
+			$filename = str_replace("/add", "/post", $filename);
246
+			$filename = str_replace("/edit", "/post", $filename);
247
+			$filename_default = str_replace("/add", "/post", $filename);
248
+			$filename_default = str_replace("/edit", "/post", $filename_default);
249
+			$filename = "web/" . $filename_default;
250
+			$filename_v3 = "web_v3/" . $filename_default;
251
+		}
252
+		$name = "ewei_shopv2";
253
+		$moduleroot = IA_ROOT . "/addons/ewei_shopv2";
254
+		if( defined("IN_SYS") ) 
255
+		{
256
+			if( !$isv3 ) 
257
+			{
258
+				$compile = IA_ROOT . "/data/tpl/web/" . $_W["template"] . "/" . $name . "/" . $filename . ".tpl.php";
259
+				$source = $moduleroot . "/template/" . $filename . ".html";
260
+				if( !is_file($source) ) 
261
+				{
262
+					$source = $moduleroot . "/template/" . $filename . "/index.html";
263
+				}
264
+			}
265
+			if( $isv3 || !is_file($source) ) 
266
+			{
267
+				if( $isv3 ) 
268
+				{
269
+					$compile = IA_ROOT . "/data/tpl/web_v3/" . $_W["template"] . "/" . $name . "/" . $filename . ".tpl.php";
270
+				}
271
+				$source = $moduleroot . "/template/" . $filename_v3 . ".html";
272
+				if( !is_file($source) ) 
273
+				{
274
+					$source = $moduleroot . "/template/" . $filename_v3 . "/index.html";
275
+				}
276
+			}
277
+			if( !is_file($source) ) 
278
+			{
279
+				$explode = array_slice(explode("/", $filename), 1);
280
+				$temp = array_slice($explode, 1);
281
+				if( $isv3 ) 
282
+				{
283
+					$source = $moduleroot . "/plugin/" . $explode[0] . "/template/web_v3/" . implode("/", $temp) . ".html";
284
+					if( !is_file($source) ) 
285
+					{
286
+						$source = $moduleroot . "/plugin/" . $explode[0] . "/template/web_v3/" . implode("/", $temp) . "/index.html";
287
+					}
288
+				}
289
+				if( !$isv3 || !is_file($source) ) 
290
+				{
291
+					$source = $moduleroot . "/plugin/" . $explode[0] . "/template/web/" . implode("/", $temp) . ".html";
292
+					if( !is_file($source) ) 
293
+					{
294
+						$source = $moduleroot . "/plugin/" . $explode[0] . "/template/web/" . implode("/", $temp) . "/index.html";
295
+					}
296
+				}
297
+			}
298
+		}
299
+		else 
300
+		{
301
+			if( $account ) 
302
+			{
303
+				$template = $_W["shopset"]["wap"]["style"];
304
+				if( empty($template) ) 
305
+				{
306
+					$template = "default";
307
+				}
308
+				if( !is_dir($moduleroot . "/template/account/" . $template) ) 
309
+				{
310
+					$template = "default";
311
+				}
312
+				$compile = IA_ROOT . "/data/tpl/app/" . $name . "/" . $template . "/account/" . $filename . ".tpl.php";
313
+				$source = IA_ROOT . "/addons/" . $name . "/template/account/" . $template . "/" . $filename . ".html";
314
+				if( !is_file($source) ) 
315
+				{
316
+					$source = IA_ROOT . "/addons/" . $name . "/template/account/default/" . $filename . ".html";
317
+				}
318
+				if( !is_file($source) ) 
319
+				{
320
+					$source = IA_ROOT . "/addons/" . $name . "/template/account/default/" . $filename . "/index.html";
321
+				}
322
+			}
323
+			else 
324
+			{
325
+				$template = m("cache")->getString("template_shop");
326
+				if( empty($template) ) 
327
+				{
328
+					$template = "default";
329
+				}
330
+				if( !is_dir($moduleroot . "/template/mobile/" . $template) ) 
331
+				{
332
+					$template = "default";
333
+				}
334
+				$compile = IA_ROOT . "/data/tpl/app/" . $name . "/" . $template . "/mobile/" . $filename . ".tpl.php";
335
+				$source = IA_ROOT . "/addons/" . $name . "/template/mobile/" . $template . "/" . $filename . ".html";
336
+				if( !is_file($source) ) 
337
+				{
338
+					$source = IA_ROOT . "/addons/" . $name . "/template/mobile/" . $template . "/" . $filename . "/index.html";
339
+				}
340
+				if( !is_file($source) ) 
341
+				{
342
+					$source = IA_ROOT . "/addons/" . $name . "/template/mobile/default/" . $filename . ".html";
343
+				}
344
+				if( !is_file($source) ) 
345
+				{
346
+					$source = IA_ROOT . "/addons/" . $name . "/template/mobile/default/" . $filename . "/index.html";
347
+				}
348
+				if( !is_file($source) ) 
349
+				{
350
+					$names = explode("/", $filename);
351
+					$pluginname = $names[0];
352
+					$ptemplate = m("cache")->getString("template_" . $pluginname);
353
+					if( empty($ptemplate) || $pluginname == "creditshop" ) 
354
+					{
355
+						$ptemplate = "default";
356
+					}
357
+					if( !is_dir($moduleroot . "/plugin/" . $pluginname . "/template/mobile/" . $ptemplate) ) 
358
+					{
359
+						$ptemplate = "default";
360
+					}
361
+					unset($names[0]);
362
+					$pfilename = implode("/", $names);
363
+					$compile = IA_ROOT . "/data/tpl/app/" . $name . "/plugin/" . $pluginname . "/" . $ptemplate . "/mobile/" . $filename . ".tpl.php";
364
+					$source = $moduleroot . "/plugin/" . $pluginname . "/template/mobile/" . $ptemplate . "/" . $pfilename . ".html";
365
+					if( !is_file($source) ) 
366
+					{
367
+						$source = $moduleroot . "/plugin/" . $pluginname . "/template/mobile/" . $ptemplate . "/" . $pfilename . "/index.html";
368
+					}
369
+					if( !is_file($source) ) 
370
+					{
371
+						$source = $moduleroot . "/plugin/" . $pluginname . "/template/mobile/default/" . $pfilename . ".html";
372
+					}
373
+					if( !is_file($source) ) 
374
+					{
375
+						$source = $moduleroot . "/plugin/" . $pluginname . "/template/mobile/default/" . $pfilename . "/index.html";
376
+					}
377
+				}
378
+			}
379
+		}
380
+		if( !is_file($source) ) 
381
+		{
382
+			exit( "Error: template source '" . $filename . "' is not exist!" );
383
+		}
384
+		if( DEVELOPMENT || !is_file($compile) || filemtime($compile) < filemtime($source) ) 
385
+		{
386
+			shop_template_compile($source, $compile, true);
387
+		}
388
+		return $compile;
389
+	}
390
+	public function template_merch($filename, $isv3) 
391
+	{
392
+		global $_W;
393
+		if( empty($filename) ) 
394
+		{
395
+			$filename = str_replace(".", "/", $_W["routes"]);
396
+		}
397
+		$filename = str_replace("/add", "/post", $filename);
398
+		$filename = str_replace("/edit", "/post", $filename);
399
+		$name = "ewei_shopv2";
400
+		$moduleroot = IA_ROOT . "/addons/ewei_shopv2";
401
+		$compile = IA_ROOT . "/data/tpl/web/" . $_W["template"] . "/merch/" . $name . "/" . $filename . ".tpl.php";
402
+		$explode = explode("/", $filename);
403
+		if( $isv3 ) 
404
+		{
405
+			$source = $moduleroot . "/plugin/merch/template/web_v3/manage/" . implode("/", $explode) . ".html";
406
+			if( !is_file($source) ) 
407
+			{
408
+				$source = $moduleroot . "/plugin/merch/template/web_v3/manage/" . implode("/", $explode) . "/index.html";
409
+			}
410
+		}
411
+		if( !$isv3 || !is_file($source) ) 
412
+		{
413
+			$source = $moduleroot . "/plugin/merch/template/web/manage/" . implode("/", $explode) . ".html";
414
+			if( !is_file($source) ) 
415
+			{
416
+				$source = $moduleroot . "/plugin/merch/template/web/manage/" . implode("/", $explode) . "/index.html";
417
+			}
418
+		}
419
+		if( !is_file($source) ) 
420
+		{
421
+			$explode = explode("/", $filename);
422
+			$temp = array_slice($explode, 1);
423
+			if( $isv3 ) 
424
+			{
425
+				$source = $moduleroot . "/plugin/" . $explode[0] . "/template/web_v3/" . implode("/", $temp) . ".html";
426
+				if( !is_file($source) ) 
427
+				{
428
+					$source = $moduleroot . "/plugin/" . $explode[0] . "/template/web_v3/" . implode("/", $temp) . "/index.html";
429
+				}
430
+			}
431
+			if( !$isv3 || !is_file($source) ) 
432
+			{
433
+				$source = $moduleroot . "/plugin/" . $explode[0] . "/template/web/" . implode("/", $temp) . ".html";
434
+				if( !is_file($source) ) 
435
+				{
436
+					$source = $moduleroot . "/plugin/" . $explode[0] . "/template/web/" . implode("/", $temp) . "/index.html";
437
+				}
438
+			}
439
+		}
440
+		if( !is_file($source) ) 
441
+		{
442
+			exit( "Error: template source '" . $filename . "' is not exist!" );
443
+		}
444
+		if( DEVELOPMENT || !is_file($compile) || filemtime($compile) < filemtime($source) ) 
445
+		{
446
+			shop_template_compile($source, $compile, true);
447
+		}
448
+		return $compile;
449
+	}
450
+	public function message($msg, $redirect = "", $type = "") 
451
+	{
452
+		global $_W;
453
+		$title = "";
454
+		$buttontext = "";
455
+		$message = $msg;
456
+		$buttondisplay = true;
457
+		if( is_array($msg) ) 
458
+		{
459
+			$message = (isset($msg["message"]) ? $msg["message"] : "");
460
+			$title = (isset($msg["title"]) ? $msg["title"] : "");
461
+			$buttontext = (isset($msg["buttontext"]) ? $msg["buttontext"] : "");
462
+			$buttondisplay = (isset($msg["buttondisplay"]) ? $msg["buttondisplay"] : true);
463
+		}
464
+		if( empty($redirect) ) 
465
+		{
466
+			$redirect = "javascript:history.back(-1);";
467
+		}
468
+		else 
469
+		{
470
+			if( $redirect == "close" ) 
471
+			{
472
+				$redirect = "javascript:WeixinJSBridge.call(\"closeWindow\")";
473
+			}
474
+			else 
475
+			{
476
+				if( $redirect == "exit" ) 
477
+				{
478
+					$redirect = "";
479
+				}
480
+			}
481
+		}
482
+		include($this->template("_message"));
483
+		exit();
484
+	}
485
+	public function checkSubmit($key, $time = 2, $message = "操作频繁,请稍后再试!") 
486
+	{
487
+		global $_W;
488
+		$open_redis = function_exists("redis") && !is_error(redis());
489
+		if( $open_redis ) 
490
+		{
491
+			$redis_key = (string) $_W["setting"]["site"]["key"] . "_" . $_W["account"]["key"] . "_" . $_W["uniacid"] . "_" . $_W["openid"] . "_mobilesubmit_" . $key;
492
+			$redis = redis();
493
+			if( $redis->setnx($redis_key, time()) ) 
494
+			{
495
+				$redis->expireAt($redis_key, time() + $time);
496
+			}
497
+			else 
498
+			{
499
+				return error(-1, $message);
500
+			}
501
+		}
502
+		return true;
503
+	}
504
+	public function checkSubmitGlobal($key, $time = 2, $message = "操作频繁,请稍后再试!") 
505
+	{
506
+		global $_W;
507
+		$open_redis = function_exists("redis") && !is_error(redis());
508
+		if( $open_redis ) 
509
+		{
510
+			$redis_key = (string) $_W["setting"]["site"]["key"] . "_" . $_W["account"]["key"] . "_" . $_W["uniacid"] . "_mobilesubmit_" . $key;
511
+			$redis = redis();
512
+			if( $redis->setnx($redis_key, time()) ) 
513
+			{
514
+				$redis->expireAt($redis_key, time() + $time);
515
+			}
516
+			else 
517
+			{
518
+				return error(-1, $message);
519
+			}
520
+		}
521
+		return true;
522
+	}
523
+}
524
+?>

+ 708 - 0
addons/ewei_shopv2/core/inc/page_mobile.php Parādīt failu

@@ -0,0 +1,708 @@
1
+<?php  if( !defined("IN_IA") ) 
2
+{
3
+	exit( "Access Denied" );
4
+}
5
+class MobilePage extends Page 
6
+{
7
+	public $footer = array( );
8
+	public $followBar = false;
9
+	protected $merch_user = array( );
10
+	public function __construct() 
11
+	{
12
+		global $_W;
13
+		global $_GPC;
14
+		m("shop")->checkClose();
15
+		$preview = intval($_GPC["preview"]);
16
+		$wap = m("common")->getSysset("wap");
17
+		if( !empty($wap["open"]) && !is_weixin() && empty($preview) ) 
18
+		{
19
+			if( $this instanceof MobileLoginPage || $this instanceof PluginMobileLoginPage ) 
20
+			{
21
+				if( empty($_W["openid"]) ) 
22
+				{
23
+					$_W["openid"] = m("account")->checkLogin();
24
+				}
25
+			}
26
+			else 
27
+			{
28
+				$_W["openid"] = m("account")->checkOpenid();
29
+			}
30
+		}
31
+		else 
32
+		{
33
+			if( $preview && !is_weixin() ) 
34
+			{
35
+				$_W["openid"] = "ooyv91cPbLRIz1qaX7Fim_cRfjZk";
36
+			}
37
+			if( EWEI_SHOPV2_DEBUG ) 
38
+			{
39
+				$_W["openid"] = "ooyv91cPbLRIz1qaX7Fim_cRfjZk";
40
+			}
41
+		}
42
+		$member = m("member")->checkMember();
43
+		$_W["mid"] = (!empty($member) ? $member["id"] : "");
44
+		$_W["mopenid"] = (!empty($member) ? $member["openid"] : "");
45
+		$merch_plugin = p("merch");
46
+		$merch_data = m("common")->getPluginset("merch");
47
+		if( !empty($_GPC["merchid"]) && $merch_plugin && $merch_data["is_openmerch"] ) 
48
+		{
49
+			$this->merch_user = pdo_fetch("select * from " . tablename("ewei_shop_merch_user") . " where id=:id limit 1", array( ":id" => intval($_GPC["merchid"]) ));
50
+		}
51
+	}
52
+	public function followBar($diypage = false, $merch = false) 
53
+	{
54
+		global $_W;
55
+		global $_GPC;
56
+		if( is_h5app() || !is_weixin() ) 
57
+		{
58
+			return NULL;
59
+		}
60
+		$openid = $_W["openid"];
61
+		$followed = m("user")->followed($openid);
62
+		$mid = intval($_GPC["mid"]);
63
+		$memberid = m("member")->getMid();
64
+		if( p("diypage") ) 
65
+		{
66
+			if( $merch && p("merch") ) 
67
+			{
68
+				$diypagedata = p("merch")->getSet("diypage", $merch);
69
+			}
70
+			else 
71
+			{
72
+				$diypagedata = m("common")->getPluginset("diypage");
73
+			}
74
+			$diyfollowbar = $diypagedata["followbar"];
75
+		}
76
+		if( $diypage ) 
77
+		{
78
+			$diyfollowbar["params"]["isopen"] = 1;
79
+		}
80
+		@session_start();
81
+		if( !$followed || !empty($diyfollowbar["params"]["showtype"]) && !empty($diyfollowbar["params"]["isopen"]) ) 
82
+		{
83
+			$set = $_W["shopset"];
84
+			$followbar = array( "followurl" => $set["share"]["followurl"], "shoplogo" => tomedia($set["shop"]["logo"]), "shopname" => $set["shop"]["name"], "qrcode" => tomedia($set["share"]["followqrcode"]), "share_member" => false );
85
+			$friend = false;
86
+			if( !empty($mid) && $memberid != $mid ) 
87
+			{
88
+				if( !empty($_SESSION[EWEI_SHOPV2_PREFIX . "_shareid"]) && $_SESSION[EWEI_SHOPV2_PREFIX . "_shareid"] == $mid ) 
89
+				{
90
+					$mid = $_SESSION[EWEI_SHOPV2_PREFIX . "_shareid"];
91
+				}
92
+				$member = m("member")->getMember($mid);
93
+				if( !empty($member) ) 
94
+				{
95
+					$_SESSION[EWEI_SHOP_PREFIX . "_shareid"] = $mid;
96
+					$friend = true;
97
+					$followbar["share_member"] = array( "id" => $member["id"], "nickname" => $member["nickname"], "realname" => $member["realname"], "avatar" => $member["avatar"] );
98
+				}
99
+			}
100
+			$showdiyfollowbar = false;
101
+			if( p("diypage") && (!empty($diyfollowbar) && !empty($diyfollowbar["params"]["isopen"]) || !empty($diyfollowbar) && $diypage) ) 
102
+			{
103
+				$showdiyfollowbar = true;
104
+				if( !empty($followbar["share_member"]) ) 
105
+				{
106
+					if( !empty($diyfollowbar["params"]["sharetext"]) ) 
107
+					{
108
+						$touser = m("member")->getMember($memberid);
109
+						$diyfollowbar["text"] = str_replace("[商城名称]", "<span style=\"color:" . $diyfollowbar["style"]["highlight"] . ";\">" . $set["shop"]["name"] . "</span>", $diyfollowbar["params"]["sharetext"]);
110
+						$diyfollowbar["text"] = str_replace("[邀请人]", "<span style=\"color:" . $diyfollowbar["style"]["highlight"] . ";\">" . $followbar["share_member"]["nickname"] . "</span>", $diyfollowbar["text"]);
111
+						$diyfollowbar["text"] = str_replace("[访问者]", "<span style=\"color:" . $diyfollowbar["style"]["highlight"] . ";\">" . $touser["nickname"] . "</span>", $diyfollowbar["text"]);
112
+					}
113
+					else 
114
+					{
115
+						$diyfollowbar["text"] = "来自好友<span class=\"text-danger\">" . $followbar["share_member"]["nickname"] . "</span>的推荐<br>" . "关注公众号,享专属服务";
116
+					}
117
+				}
118
+				else 
119
+				{
120
+					if( !empty($diyfollowbar["params"]["defaulttext"]) ) 
121
+					{
122
+						$diyfollowbar["text"] = str_replace("[商城名称]", "<span style=\"color:" . $diyfollowbar["style"]["highlight"] . ";\">" . $set["shop"]["name"] . "</span>", $diyfollowbar["params"]["defaulttext"]);
123
+					}
124
+					else 
125
+					{
126
+						$diyfollowbar["text"] = "欢迎进入<span class=\"text-danger\">" . $set["shop"]["name"] . "</span><br>" . "关注公众号,享专属服务";
127
+					}
128
+				}
129
+				$diyfollowbar["text"] = nl2br($diyfollowbar["text"]);
130
+				$diyfollowbar["logo"] = tomedia($set["shop"]["logo"]);
131
+				if( $diyfollowbar["params"]["icontype"] == 1 && !empty($followbar["share_member"]) ) 
132
+				{
133
+					$diyfollowbar["logo"] = tomedia($followbar["share_member"]["avatar"]);
134
+				}
135
+				else 
136
+				{
137
+					if( $diyfollowbar["params"]["icontype"] == 3 && !empty($diyfollowbar["params"]["iconurl"]) ) 
138
+					{
139
+						$diyfollowbar["logo"] = tomedia($diyfollowbar["params"]["iconurl"]);
140
+					}
141
+				}
142
+				if( empty($diyfollowbar["params"]["btnclick"]) ) 
143
+				{
144
+					if( empty($diyfollowbar["params"]["btnlinktype"]) ) 
145
+					{
146
+						$diyfollowbar["link"] = $set["share"]["followurl"];
147
+					}
148
+					else 
149
+					{
150
+						$diyfollowbar["link"] = $diyfollowbar["params"]["btnlink"];
151
+					}
152
+				}
153
+				else 
154
+				{
155
+					if( empty($diyfollowbar["params"]["qrcodetype"]) ) 
156
+					{
157
+						$diyfollowbar["qrcode"] = tomedia($set["share"]["followqrcode"]);
158
+					}
159
+					else 
160
+					{
161
+						$diyfollowbar["qrcode"] = tomedia($diyfollowbar["params"]["qrcodeurl"]);
162
+					}
163
+				}
164
+			}
165
+			if( $showdiyfollowbar ) 
166
+			{
167
+				include($this->template("diypage/followbar"));
168
+			}
169
+			else 
170
+			{
171
+				include($this->template("_followbar"));
172
+			}
173
+		}
174
+	}
175
+	public function MemberBar($diypage = false, $merch = false) 
176
+	{
177
+		global $_W;
178
+		global $_GPC;
179
+		if( is_h5app() || !is_weixin() ) 
180
+		{
181
+			return NULL;
182
+		}
183
+		$mid = intval($_GPC["mid"]);
184
+		$cmember_plugin = p("cmember");
185
+		if( !$cmember_plugin ) 
186
+		{
187
+			return NULL;
188
+		}
189
+		$openid = $_W["openid"];
190
+		$followed = m("user")->followed($openid);
191
+		if( !$followed ) 
192
+		{
193
+			return NULL;
194
+		}
195
+		$check = $cmember_plugin->checkMember($openid);
196
+		if( !empty($check) ) 
197
+		{
198
+			return NULL;
199
+		}
200
+		$data = m("common")->getPluginset("commission");
201
+		if( !empty($data["become_goodsid"]) ) 
202
+		{
203
+			$goods = pdo_fetch("select id,title,thumb from " . tablename("ewei_shop_goods") . " where id=:id and uniacid=:uniacid limit 1 ", array( ":id" => $data["become_goodsid"], ":uniacid" => $_W["uniacid"] ));
204
+			$buy_member_url = mobileUrl("goods/detail", array( "id" => $goods["id"], "mid" => $mid ));
205
+			include($this->template("cmember/_memberbar"));
206
+		}
207
+		else 
208
+		{
209
+			return NULL;
210
+		}
211
+	}
212
+	public function footerMenus($diymenuid = NULL, $ismerch = false, $texts = array( )) 
213
+	{
214
+		global $_W;
215
+		global $_GPC;
216
+		$params = array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] );
217
+		$cartcount = pdo_fetchcolumn("select ifnull(sum(total),0) from " . tablename("ewei_shop_member_cart") . " where uniacid=:uniacid and openid=:openid and deleted=0 and isnewstore=0  and selected =1", $params);
218
+		$commission = array( );
219
+		if( p("commission") && intval(0 < $_W["shopset"]["commission"]["level"]) ) 
220
+		{
221
+			$member = m("member")->getMember($_W["openid"]);
222
+			if( !$member["agentblack"] ) 
223
+			{
224
+				if( $member["isagent"] == 1 && $member["status"] == 1 ) 
225
+				{
226
+					$commission = array( "url" => mobileUrl("commission"), "text" => (empty($_W["shopset"]["commission"]["texts"]["center"]) ? "分销中心" : $_W["shopset"]["commission"]["texts"]["center"]) );
227
+				}
228
+				else 
229
+				{
230
+					$commission = array( "url" => mobileUrl("commission/register"), "text" => (empty($_W["shopset"]["commission"]["texts"]["become"]) ? "成为分销商" : $_W["shopset"]["commission"]["texts"]["become"]) );
231
+				}
232
+			}
233
+		}
234
+		$showdiymenu = false;
235
+		$routes = explode(".", $_W["routes"]);
236
+		$controller = $routes[0];
237
+		if( $controller == "member" || $controller == "cart" || $controller == "order" || $controller == "goods" || $controller == "quick" ) 
238
+		{
239
+			$controller = "shop";
240
+		}
241
+		if( empty($diymenuid) ) 
242
+		{
243
+			$pageid = (!empty($controller) ? $controller : "shop");
244
+			$pageid = ($pageid == "index" ? "shop" : $pageid);
245
+			if( !empty($_GPC["merchid"]) && ($_W["routes"] == "shop.category" || $_W["routes"] == "goods") ) 
246
+			{
247
+				$pageid = "merch";
248
+			}
249
+			if( $pageid == "sale" && $_W["routes"] == "sale.coupon.my.showcoupongoods" ) 
250
+			{
251
+				$pageid = "shop";
252
+			}
253
+			if( $pageid == "merch" && !empty($_GPC["merchid"]) && p("merch") ) 
254
+			{
255
+				$merchdata = p("merch")->getSet("diypage", $_GPC["merchid"]);
256
+				if( !empty($merchdata["menu"]) ) 
257
+				{
258
+					$diymenuid = $merchdata["menu"]["shop"];
259
+					if( !is_weixin() || is_h5app() ) 
260
+					{
261
+						$diymenuid = $merchdata["menu"]["shop_wap"];
262
+					}
263
+				}
264
+			}
265
+			else 
266
+			{
267
+				$diypagedata = m("common")->getPluginset("diypage");
268
+				if( !empty($diypagedata["menu"]) ) 
269
+				{
270
+					$diymenuid = $diypagedata["menu"][$pageid];
271
+					if( !is_weixin() || is_h5app() ) 
272
+					{
273
+						$diymenuid = $diypagedata["menu"][$pageid . "_wap"];
274
+					}
275
+				}
276
+			}
277
+		}
278
+		if( !empty($diymenuid) ) 
279
+		{
280
+			$menu = pdo_fetch("SELECT * FROM " . tablename("ewei_shop_diypage_menu") . " WHERE id=:id and uniacid=:uniacid limit 1 ", array( ":id" => $diymenuid, ":uniacid" => $_W["uniacid"] ));
281
+			if( !empty($menu) ) 
282
+			{
283
+				$menu = $menu["data"];
284
+				$menu = base64_decode($menu);
285
+				$diymenu = json_decode($menu, true);
286
+				$showdiymenu = true;
287
+			}
288
+		}
289
+		if( $showdiymenu ) 
290
+		{
291
+			include($this->template("diypage/menu"));
292
+		}
293
+		else 
294
+		{
295
+			if( $controller == "commission" && $routes[1] != "myshop" ) 
296
+			{
297
+				include($this->template("commission/_menu"));
298
+			}
299
+			else 
300
+			{
301
+				if( $controller == "creditshop" ) 
302
+				{
303
+					include($this->template("creditshop/_menu"));
304
+				}
305
+				else 
306
+				{
307
+					if( $controller == "groups" ) 
308
+					{
309
+						include($this->template("groups/_groups_footer"));
310
+					}
311
+					else 
312
+					{
313
+						if( $controller == "merch" ) 
314
+						{
315
+							include($this->template("merch/_menu"));
316
+						}
317
+						else 
318
+						{
319
+							if( $controller == "mr" ) 
320
+							{
321
+								include($this->template("mr/_menu"));
322
+							}
323
+							else 
324
+							{
325
+								if( $controller == "newmr" ) 
326
+								{
327
+									include($this->template("newmr/_menu"));
328
+								}
329
+								else 
330
+								{
331
+									if( $controller == "sign" ) 
332
+									{
333
+										include($this->template("sign/_menu"));
334
+									}
335
+									else 
336
+									{
337
+										if( $controller == "sns" ) 
338
+										{
339
+											include($this->template("sns/_menu"));
340
+										}
341
+										else 
342
+										{
343
+											if( $controller == "seckill" ) 
344
+											{
345
+												include($this->template("seckill/_menu"));
346
+											}
347
+											else 
348
+											{
349
+												if( $controller == "mmanage" ) 
350
+												{
351
+													include($this->template("mmanage/_menu"));
352
+												}
353
+												else 
354
+												{
355
+													if( $ismerch ) 
356
+													{
357
+														include($this->template("merch/_menu"));
358
+													}
359
+													else 
360
+													{
361
+														include($this->template("_menu"));
362
+													}
363
+												}
364
+											}
365
+										}
366
+									}
367
+								}
368
+							}
369
+						}
370
+					}
371
+				}
372
+			}
373
+		}
374
+	}
375
+	public function shopShare() 
376
+	{
377
+		global $_W;
378
+		global $_GPC;
379
+		$trigger = false;
380
+		if( empty($_W["shopshare"]) ) 
381
+		{
382
+			$set = $_W["shopset"];
383
+			$_W["shopshare"] = array( "title" => (empty($set["share"]["title"]) ? $set["shop"]["name"] : $set["share"]["title"]), "imgUrl" => (empty($set["share"]["icon"]) ? tomedia($set["shop"]["logo"]) : tomedia($set["share"]["icon"])), "desc" => (empty($set["share"]["desc"]) ? $set["shop"]["description"] : $set["share"]["desc"]), "link" => (empty($set["share"]["url"]) ? mobileUrl("", NULL, true) : $set["share"]["url"]) );
384
+			$plugin_commission = p("commission");
385
+			if( $plugin_commission ) 
386
+			{
387
+				$set = $plugin_commission->getSet();
388
+				if( !empty($set["level"]) ) 
389
+				{
390
+					$openid = $_W["openid"];
391
+					$member = m("member")->getMember($openid);
392
+					if( !empty($member) && $member["status"] == 1 && $member["isagent"] == 1 ) 
393
+					{
394
+						if( empty($set["closemyshop"]) ) 
395
+						{
396
+							$myshop = $plugin_commission->getShop($member["id"]);
397
+							$_W["shopshare"] = array( "title" => $myshop["name"], "imgUrl" => tomedia($myshop["logo"]), "desc" => $myshop["desc"], "link" => mobileUrl("commission/myshop", array( "mid" => $member["id"] ), true) );
398
+						}
399
+						else 
400
+						{
401
+							$_W["shopshare"]["link"] = (empty($_W["shopset"]["share"]["url"]) ? mobileUrl("", array( "mid" => $member["id"] ), true) : $_W["shopset"]["share"]["url"]);
402
+						}
403
+						if( empty($set["become_reg"]) && (empty($member["realname"]) || empty($member["mobile"])) ) 
404
+						{
405
+							$trigger = true;
406
+						}
407
+					}
408
+					else 
409
+					{
410
+						if( !empty($_GPC["mid"]) ) 
411
+						{
412
+							$m = m("member")->getMember($_GPC["mid"]);
413
+							if( !empty($m) && $m["status"] == 1 && $m["isagent"] == 1 ) 
414
+							{
415
+								if( empty($set["closemyshop"]) ) 
416
+								{
417
+									$myshop = $plugin_commission->getShop($_GPC["mid"]);
418
+									$_W["shopshare"] = array( "title" => $myshop["name"], "imgUrl" => tomedia($myshop["logo"]), "desc" => $myshop["desc"], "link" => mobileUrl("commission/myshop", array( "mid" => $member["id"] ), true) );
419
+								}
420
+								else 
421
+								{
422
+									$_W["shopshare"]["link"] = (empty($_W["shopset"]["share"]["url"]) ? mobileUrl("", array( "mid" => $_GPC["mid"] ), true) : $_W["shopset"]["share"]["url"]);
423
+								}
424
+							}
425
+							else 
426
+							{
427
+								$_W["shopshare"]["link"] = (empty($_W["shopset"]["share"]["url"]) ? mobileUrl("", array( "mid" => $_GPC["mid"] ), true) : $_W["shopset"]["share"]["url"]);
428
+							}
429
+						}
430
+					}
431
+				}
432
+			}
433
+		}
434
+		return $trigger;
435
+	}
436
+	public function diyPage($type) 
437
+	{
438
+		global $_W;
439
+		global $_GPC;
440
+		if( empty($type) || !p("diypage") ) 
441
+		{
442
+			return false;
443
+		}
444
+		$canmembercard = m("plugin")->permission("membercard");
445
+		$merch = intval($_GPC["merchid"]);
446
+		if( $merch && $type != "member" && $type != "commission" ) 
447
+		{
448
+			if( !p("merch") ) 
449
+			{
450
+				return false;
451
+			}
452
+			$diypagedata = p("merch")->getSet("diypage", $merch);
453
+		}
454
+		else 
455
+		{
456
+			$diypagedata = m("common")->getPluginset("diypage");
457
+			if( p("commission") ) 
458
+			{
459
+				$comm_set = p("commission")->getSet();
460
+			}
461
+		}
462
+		if( !empty($diypagedata) ) 
463
+		{
464
+			$diypageid = $diypagedata["page"][$type];
465
+			if( !empty($diypageid) ) 
466
+			{
467
+				$page = p("diypage")->getPage($diypageid, true);
468
+				if( !empty($page) ) 
469
+				{
470
+					p("diypage")->setShare($page);
471
+					$diyitems = $page["data"]["items"];
472
+					$diyitem_search = array( );
473
+					$diy_topmenu = array( );
474
+					if( !empty($diyitems) && is_array($diyitems) ) 
475
+					{
476
+						$jsondiyitems = json_encode($diyitems);
477
+						if( strexists($jsondiyitems, "fixedsearch") || strexists($jsondiyitems, "topmenu") ) 
478
+						{
479
+							foreach( $diyitems as $diyitemid => $diyitem ) 
480
+							{
481
+								if( $diyitem["id"] == "fixedsearch" ) 
482
+								{
483
+									$diyitem_search = $diyitem;
484
+									unset($diyitems[$diyitemid]);
485
+								}
486
+								else 
487
+								{
488
+									if( $diyitem["id"] == "topmenu" ) 
489
+									{
490
+										$diy_topmenu = $diyitem;
491
+									}
492
+								}
493
+							}
494
+							unset($diyitem);
495
+						}
496
+					}
497
+					$startadv = p("diypage")->getStartAdv($page["diyadv"]);
498
+					if( $type == "home" ) 
499
+					{
500
+						$cpinfos = false;
501
+						if( com("coupon") ) 
502
+						{
503
+							$cpinfos = com("coupon")->getInfo();
504
+						}
505
+						$trade = m("common")->getSysset("trade");
506
+						if( empty($trade["shop_strengthen"]) ) 
507
+						{
508
+							$order = pdo_fetch("select id,price  from " . tablename("ewei_shop_order") . " where uniacid=:uniacid and status = 0 and paytype<>3 and openid=:openid order by createtime desc limit 1", array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] ));
509
+							if( !empty($order) ) 
510
+							{
511
+								$goods = pdo_fetchall("select g.*,og.total as totals  from " . tablename("ewei_shop_order_goods") . " og inner join " . tablename("ewei_shop_goods") . " g on og.goodsid = g.id   where og.uniacid=:uniacid    and og.orderid=:orderid  limit 3", array( ":uniacid" => $_W["uniacid"], ":orderid" => $order["id"] ));
512
+								$goodstotal = pdo_fetchcolumn("select COUNT(*)  from " . tablename("ewei_shop_order_goods") . " og inner join " . tablename("ewei_shop_goods") . " g on og.goodsid = g.id   where og.uniacid=:uniacid    and og.orderid=:orderid ", array( ":uniacid" => $_W["uniacid"], ":orderid" => $order["id"] ));
513
+							}
514
+						}
515
+					}
516
+					include($this->template("diypage"));
517
+					exit();
518
+				}
519
+			}
520
+		}
521
+	}
522
+	public function diyLayer($v = false, $diy = false, $merch = false) 
523
+	{
524
+		global $_W;
525
+		global $_GPC;
526
+		if( !p("diypage") || $diy ) 
527
+		{
528
+			return NULL;
529
+		}
530
+		if( $merch ) 
531
+		{
532
+			if( !p("merch") ) 
533
+			{
534
+				return false;
535
+			}
536
+			$diypagedata = p("merch")->getSet("diypage", $merch);
537
+		}
538
+		else 
539
+		{
540
+			$diypagedata = m("common")->getPluginset("diypage");
541
+		}
542
+		if( !empty($diypagedata) ) 
543
+		{
544
+			$diylayer = $diypagedata["layer"];
545
+			if( empty($diylayer["params"]["imgurl"]) ) 
546
+			{
547
+				return false;
548
+			}
549
+			if( !$diylayer["params"]["isopen"] && $v ) 
550
+			{
551
+				return NULL;
552
+			}
553
+			include($this->template("diypage/layer"));
554
+		}
555
+	}
556
+	public function diyGotop($v = false, $diy = false, $merch = false) 
557
+	{
558
+		global $_W;
559
+		global $_GPC;
560
+		if( !p("diypage") || $diy ) 
561
+		{
562
+			return NULL;
563
+		}
564
+		if( $merch ) 
565
+		{
566
+			if( !p("merch") ) 
567
+			{
568
+				return false;
569
+			}
570
+			$diypagedata = p("merch")->getSet("diypage", $merch);
571
+			$page = p("diypage")->getPage($diypagedata["page"]["home"], true);
572
+		}
573
+		else 
574
+		{
575
+			$diypagedata = m("common")->getPluginset("diypage");
576
+		}
577
+		if( !empty($diypagedata) ) 
578
+		{
579
+			$diygotop = $diypagedata["gotop"];
580
+			if( $merch ) 
581
+			{
582
+				if( !$page["data"]["page"]["diygotop"] ) 
583
+				{
584
+					return NULL;
585
+				}
586
+			}
587
+			else 
588
+			{
589
+				if( !$diygotop["params"]["isopen"] && $v ) 
590
+				{
591
+					return NULL;
592
+				}
593
+			}
594
+			include($this->template("diypage/gotop"));
595
+		}
596
+	}
597
+	public function diyDanmu($diy = false) 
598
+	{
599
+		global $_W;
600
+		global $_GPC;
601
+		if( !p("diypage") ) 
602
+		{
603
+			return NULL;
604
+		}
605
+		$diypagedata = m("common")->getPluginset("diypage");
606
+		$danmu = $diypagedata["danmu"];
607
+		if( empty($danmu) || !$diy && empty($danmu["params"]["isopen"]) ) 
608
+		{
609
+			return NULL;
610
+		}
611
+		if( empty($danmu["params"]["datatype"]) ) 
612
+		{
613
+			$condition = (!empty($_W["openid"]) ? " AND openid!='" . $_W["openid"] . "' " : "");
614
+			$danmu["data"] = pdo_fetchall("SELECT nickname, avatar as imgurl FROM" . tablename("ewei_shop_member") . " WHERE uniacid=:uniacid AND nickname!='' AND avatar!='' " . $condition . " ORDER BY rand() LIMIT 10", array( ":uniacid" => $_W["uniacid"] ));
615
+			$randstart = (!empty($danmu["params"]["starttime"]) ? intval($danmu["params"]["starttime"]) : 0);
616
+			$randend = (!empty($danmu["params"]["endtime"]) ? intval($danmu["params"]["endtime"]) : 0);
617
+			if( $randend <= $randstart ) 
618
+			{
619
+				$randend = $randend + rand(100, 999);
620
+			}
621
+		}
622
+		else 
623
+		{
624
+			if( $danmu["params"]["datatype"] == 1 ) 
625
+			{
626
+				$danmu["data"] = pdo_fetchall("SELECT m.nickname, m.avatar as imgurl, o.createtime as time FROM" . tablename("ewei_shop_order") . " o LEFT JOIN " . tablename("ewei_shop_member") . " m ON m.openid=o.openid WHERE o.uniacid=:uniacid AND m.nickname!='' AND m.avatar!='' ORDER BY o.createtime DESC LIMIT 10", array( ":uniacid" => $_W["uniacid"] ));
627
+			}
628
+			else 
629
+			{
630
+				if( $danmu["params"]["datatype"] == 2 ) 
631
+				{
632
+					$danmu["data"] = set_medias($danmu["data"], "imgurl");
633
+				}
634
+			}
635
+		}
636
+		if( empty($danmu["data"]) || !is_array($danmu["data"]) ) 
637
+		{
638
+			return NULL;
639
+		}
640
+		foreach( $danmu["data"] as $index => $item ) 
641
+		{
642
+			if( strpos($item["nickname"], "'") !== false ) 
643
+			{
644
+				$danmu["data"][$index]["nickname"] = str_replace("'", "`", $item["nickname"]);
645
+				$danmu["data"][$index]["nickname"] = str_replace("\"", "`", $danmu["data"][$index]["nickname"]);
646
+				$danmu["data"][$index]["nickname"] = str_replace(PHP_EOL, "", $danmu["data"][$index]["nickname"]);
647
+			}
648
+			if( empty($danmu["params"]["datatype"]) ) 
649
+			{
650
+				$time = rand($randstart, $randend);
651
+				$danmu["data"][$index]["time"] = p("diypage")->getDanmuTime($time);
652
+			}
653
+			else 
654
+			{
655
+				if( $danmu["params"]["datatype"] == 1 ) 
656
+				{
657
+					$danmu["data"][$index]["time"] = p("diypage")->getDanmuTime(time() - $item["time"]);
658
+				}
659
+				else 
660
+				{
661
+					if( $danmu["params"]["datatype"] == 2 ) 
662
+					{
663
+						$danmu["data"][$index]["time"] = p("diypage")->getDanmuTime($danmu["data"][$index]["time"]);
664
+					}
665
+				}
666
+			}
667
+		}
668
+		include($this->template("diypage/danmu"));
669
+	}
670
+	public function backliving() 
671
+	{
672
+		global $_W;
673
+		global $_GPC;
674
+		if( !p("live") ) 
675
+		{
676
+			return NULL;
677
+		}
678
+		if( strexists($_W["routes"], "live") ) 
679
+		{
680
+			return false;
681
+		}
682
+		$liveid = intval($_GPC["liveid"]);
683
+		if( empty($liveid) ) 
684
+		{
685
+			return NULL;
686
+		}
687
+		$living = p("live")->isLiving($liveid);
688
+		if( !$living ) 
689
+		{
690
+			return NULL;
691
+		}
692
+		include($this->template("live/backliving"));
693
+	}
694
+	public function wapQrcode() 
695
+	{
696
+		global $_W;
697
+		global $_GPC;
698
+		$currenturl = "";
699
+		if( !is_mobile() ) 
700
+		{
701
+			$currenturl = (string) $_W["siteroot"] . "app/index.php?" . $_SERVER["QUERY_STRING"];
702
+		}
703
+		$shop = m("common")->getSysset("shop");
704
+		$shopname = $shop["name"];
705
+		include($this->template("_wapqrcode"));
706
+	}
707
+}
708
+?>

+ 16 - 0
addons/ewei_shopv2/core/inc/page_mobile_login.php Parādīt failu

@@ -0,0 +1,16 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class MobileLoginPage extends MobilePage
7
+{
8
+	public function __construct()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		parent::__construct();
13
+	}
14
+}
15
+
16
+?>

+ 33 - 0
addons/ewei_shopv2/core/inc/page_mobile_plugin.php Parādīt failu

@@ -0,0 +1,33 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class PluginMobilePage extends MobilePage
7
+{
8
+	public $model;
9
+	public $set;
10
+
11
+	public function __construct()
12
+	{
13
+		parent::__construct();
14
+		$this->model = m('plugin')->loadModel($GLOBALS['_W']['plugin']);
15
+		$this->set = $this->model->getSet();
16
+	}
17
+
18
+	public function getSet()
19
+	{
20
+		return $this->set;
21
+	}
22
+
23
+	public function qr()
24
+	{
25
+		global $_W;
26
+		global $_GPC;
27
+		$url = trim($_GPC['url']);
28
+		require IA_ROOT . '/framework/library/qrcode/phpqrcode.php';
29
+		QRcode::png($url, false, QR_ECLEVEL_L, 16, 1);
30
+	}
31
+}
32
+
33
+?>

+ 16 - 0
addons/ewei_shopv2/core/inc/page_mobile_plugin_login.php Parādīt failu

@@ -0,0 +1,16 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class PluginMobileLoginPage extends PluginMobilePage
7
+{
8
+	public function __construct()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		parent::__construct();
13
+	}
14
+}
15
+
16
+?>

+ 24 - 0
addons/ewei_shopv2/core/inc/page_mobile_plugin_pf.php Parādīt failu

@@ -0,0 +1,24 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class PluginPfMobilePage extends Page
7
+{
8
+	public $model;
9
+	public $set;
10
+
11
+	public function __construct()
12
+	{
13
+		m('shop')->checkClose();
14
+		$this->model = m('plugin')->loadModel($GLOBALS['_W']['plugin']);
15
+		$this->set = $this->model->getSet();
16
+	}
17
+
18
+	public function getSet()
19
+	{
20
+		return $this->set;
21
+	}
22
+}
23
+
24
+?>

+ 21 - 0
addons/ewei_shopv2/core/inc/page_system.php Parādīt failu

@@ -0,0 +1,21 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class SystemPage extends WebPage
7
+{
8
+	public function __construct()
9
+	{
10
+		parent::__construct(false);
11
+		global $_W;
12
+		define('IS_EWEI_SHOPV2_SYSTEM', true);
13
+		$routes = explode('.', $_W['routes']);
14
+		$_W['current_menu'] = isset($routes[1]) ? $routes[1] : '';
15
+		if (!$_W['isfounder'] || $_W['role'] == 'vice_founder') {
16
+			$this->message('您无权访问');
17
+		}
18
+	}
19
+}
20
+
21
+?>

+ 126 - 0
addons/ewei_shopv2/core/inc/page_web.php Parādīt failu

@@ -0,0 +1,126 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class WebPage extends Page
7
+{
8
+	public function __construct($_init = true)
9
+	{
10
+		if ($_init) {
11
+			$this->init();
12
+		}
13
+
14
+		$GLOBALS['_W']['shopversion'] = 1;
15
+	}
16
+
17
+	private function init()
18
+	{
19
+		global $_W;
20
+		if ($_W['role'] != 'manager' && $_W['role'] != 'founder' && $_W['routes'] != 'shop') {
21
+			$perm = cv($_W['routes']);
22
+
23
+			if (com('perm')) {
24
+				$perm_type = com('perm')->getLogTypes(true);
25
+				$perm_type_value = array();
26
+
27
+				foreach ($perm_type as $val) {
28
+					$perm_type_value[] = $val['value'];
29
+				}
30
+
31
+				$is_xxx = com('perm')->check_xxx($_W['routes']);
32
+
33
+				if ($is_xxx) {
34
+					if (!$perm) {
35
+						foreach ($is_xxx as $item) {
36
+							if (in_array($item, $perm_type_value)) {
37
+								$this->message('你没有相应的权限查看');
38
+							}
39
+						}
40
+					}
41
+				}
42
+				else {
43
+					if (strexists($_W['routes'], 'edit')) {
44
+						if (!cv($_W['routes'])) {
45
+							$view = str_replace('edit', 'view', $_W['routes']);
46
+							$perm_view = cv($view);
47
+						}
48
+					}
49
+					else {
50
+						$main = $_W['routes'] . '.main';
51
+						$perm_main = cv($main);
52
+						if (!$perm_main && in_array($main, $perm_type_value)) {
53
+							$this->message('你没有相应的权限查看');
54
+						}
55
+						else {
56
+							if (!$perm && in_array($_W['routes'], $perm_type_value)) {
57
+								$this->message('你没有相应的权限查看');
58
+							}
59
+						}
60
+					}
61
+
62
+					if (isset($perm_view) && !$perm_view) {
63
+						$this->message('你没有相应的权限查看');
64
+					}
65
+				}
66
+			}
67
+		}
68
+
69
+		if ($_W['ispost']) {
70
+			rc();
71
+		}
72
+
73
+		m('system')->history_url();
74
+	}
75
+
76
+	public function isOpenPlugin()
77
+	{
78
+		$name = com_run('perm::allPerms');
79
+		unset($name['shop']);
80
+		unset($name['goods']);
81
+		unset($name['member']);
82
+		unset($name['order']);
83
+		unset($name['finance']);
84
+		unset($name['statistics']);
85
+		unset($name['sysset']);
86
+		unset($name['sale']);
87
+		$name_keys = array_keys($name);
88
+		return implode('|', $name_keys);
89
+	}
90
+
91
+	public function frame_menus()
92
+	{
93
+		global $_GPC;
94
+		global $_W;
95
+
96
+		if ($_W['plugin']) {
97
+			include $this->template($_W['plugin'] . '/tabs');
98
+		}
99
+		else if ($_W['controller'] == 'system') {
100
+			$routes = explode('.', $_W['routes']);
101
+			$tabs = $routes[0] . (isset($routes[1]) ? '/' . $routes[1] : '') . '/tabs';
102
+			include $this->template($tabs);
103
+		}
104
+		else {
105
+			include $this->template($_W['controller'] . '/tabs');
106
+		}
107
+	}
108
+
109
+	public function show_funbar()
110
+	{
111
+		global $_W;
112
+		$funbardata = pdo_fetch('select * from ' . tablename('ewei_shop_funbar') . ' where uid=:uid and uniacid=:uniacid limit 1', array(':uid' => $_W['uid'], ':uniacid' => $_W['uniacid']));
113
+		if (!empty($funbardata['datas']) && !is_array($funbardata['datas'])) {
114
+			if (strexists($funbardata['datas'], '{"')) {
115
+				$funbardata['datas'] = json_decode($funbardata['datas'], true);
116
+			}
117
+			else {
118
+				$funbardata['datas'] = unserialize($funbardata['datas']);
119
+			}
120
+		}
121
+
122
+		include $this->template('funbar');
123
+	}
124
+}
125
+
126
+?>

+ 17 - 0
addons/ewei_shopv2/core/inc/page_web_com.php Parādīt failu

@@ -0,0 +1,17 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class ComWebPage extends WebPage
7
+{
8
+	public function __construct($_com = '')
9
+	{
10
+		parent::__construct();
11
+		if (com('perm') && !com('perm')->check_com($_com)) {
12
+			$this->message('你没有相应的权限查看');
13
+		}
14
+	}
15
+}
16
+
17
+?>

+ 43 - 0
addons/ewei_shopv2/core/inc/page_web_plugin.php Parādīt failu

@@ -0,0 +1,43 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class PluginWebPage extends WebPage
7
+{
8
+	public $pluginname;
9
+	public $model;
10
+	public $plugintitle;
11
+	public $set;
12
+
13
+	public function __construct($_init = true)
14
+	{
15
+		parent::__construct($_init);
16
+		global $_W;
17
+		if (com('perm') && !com('perm')->check_plugin($_W['plugin'])) {
18
+			$this->message('你没有相应的权限查看');
19
+		}
20
+
21
+		$this->pluginname = $_W['plugin'];
22
+		$this->modulename = 'ewei_shopv2';
23
+		$this->plugintitle = m('plugin')->getName($this->pluginname);
24
+		$this->model = m('plugin')->loadModel($this->pluginname);
25
+		$this->set = $this->model->getSet();
26
+
27
+		if ($_W['ispost']) {
28
+			rc($this->pluginname);
29
+		}
30
+	}
31
+
32
+	public function getSet()
33
+	{
34
+		return $this->set;
35
+	}
36
+
37
+	public function updateSet($data = array())
38
+	{
39
+		$this->model->updateSet($data);
40
+	}
41
+}
42
+
43
+?>

+ 77 - 0
addons/ewei_shopv2/core/inc/plugin_model.php Parādīt failu

@@ -0,0 +1,77 @@
1
+<?php
2
+class PluginModel
3
+{
4
+	private $pluginname;
5
+	private $set;
6
+
7
+	public function __construct($name = '')
8
+	{
9
+		$this->pluginname = $name;
10
+		$this->set = $this->getSet();
11
+	}
12
+
13
+	public function getSet()
14
+	{
15
+		if (empty($GLOBALS['_S'][$this->pluginname])) {
16
+			return m('common')->getPluginset($this->pluginname);
17
+		}
18
+
19
+		return $GLOBALS['_S'][$this->pluginname];
20
+	}
21
+
22
+	public function updateSet($data = array())
23
+	{
24
+		m('common')->updatePluginset(array($this->pluginname => $data));
25
+	}
26
+
27
+	public function getName()
28
+	{
29
+		return pdo_fetchcolumn('select name from ' . tablename('ewei_shop_plugin') . ' where identity=:identity limit 1', array(':identity' => $this->pluginname));
30
+	}
31
+
32
+	public function checkSubmit($key, $time = 2, $message = '操作频繁,请稍后再试!')
33
+	{
34
+		global $_W;
35
+		$open_redis = function_exists('redis') && !is_error(redis());
36
+
37
+		if ($open_redis) {
38
+			$redis_key = $_W['setting']['site']['key'] . '_' . $_W['account']['key'] . '_' . $_W['uniacid'] . '_' . $_W['openid'] . '_mobilesubmit_' . $key;
39
+			$redis = redis();
40
+
41
+			if ($redis->setnx($redis_key, time())) {
42
+				$redis->expireAt($redis_key, time() + $time);
43
+			}
44
+			else {
45
+				return error(-1, $message);
46
+			}
47
+		}
48
+
49
+		return true;
50
+	}
51
+
52
+	public function checkSubmitGlobal($key, $time = 2, $message = '操作频繁,请稍后再试!')
53
+	{
54
+		global $_W;
55
+		$open_redis = function_exists('redis') && !is_error(redis());
56
+
57
+		if ($open_redis) {
58
+			$redis_key = $_W['setting']['site']['key'] . '_' . $_W['account']['key'] . '_' . $_W['uniacid'] . '_mobilesubmit_' . $key;
59
+			$redis = redis();
60
+
61
+			if ($redis->setnx($redis_key, time())) {
62
+				$redis->expireAt($redis_key, time() + $time);
63
+			}
64
+			else {
65
+				return error(-1, $message);
66
+			}
67
+		}
68
+
69
+		return true;
70
+	}
71
+}
72
+
73
+if (!defined('IN_IA')) {
74
+	exit('Access Denied');
75
+}
76
+
77
+?>

+ 49 - 0
addons/ewei_shopv2/core/inc/plugin_processor.php Parādīt failu

@@ -0,0 +1,49 @@
1
+<?php
2
+if (!(defined('IN_IA'))) 
3
+{
4
+	exit('Access Denied');
5
+}
6
+require dirname(__DIR__) . '/../defines.php';
7
+class PluginProcessor extends WeModuleProcessor 
8
+{
9
+	public $model;
10
+	public $modulename;
11
+	public $message;
12
+	public function __construct($name = '') 
13
+	{
14
+		global $_W;
15
+		$this->modulename = 'ewei_shopv2';
16
+		$this->pluginname = $name;
17
+		$secure = $this->getIsSecureConnection();
18
+		$http = (($secure ? 'https' : 'http'));
19
+		$_W['siteroot'] = ((strexists($_W['siteroot'], 'https://') ? $_W['siteroot'] : str_replace('http', $http, $_W['siteroot'])));
20
+		$this->loadModel();
21
+	}
22
+	private function loadModel() 
23
+	{
24
+		$modelfile = IA_ROOT . '/addons/' . $this->modulename . '/plugin/' . $this->pluginname . '/core/model.php';
25
+		if (is_file($modelfile)) 
26
+		{
27
+			$classname = ucfirst($this->pluginname) . 'Model';
28
+			require $modelfile;
29
+			$this->model = new $classname($this->pluginname);
30
+		}
31
+	}
32
+	public function respond($obj = '') 
33
+	{
34
+		$this->message = $this->message;
35
+	}
36
+	public function getIsSecureConnection() 
37
+	{
38
+		if (isset($_SERVER['HTTPS']) && (('1' == $_SERVER['HTTPS']) || ('on' == strtolower($_SERVER['HTTPS'])))) 
39
+		{
40
+			return true;
41
+		}
42
+		if (isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'])) 
43
+		{
44
+			return true;
45
+		}
46
+		return false;
47
+	}
48
+}
49
+?>

+ 48 - 0
addons/ewei_shopv2/core/inc/processor.php Parādīt failu

@@ -0,0 +1,48 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Processor extends WeModuleProcessor
7
+{
8
+	public function respond()
9
+	{
10
+		$rule = pdo_fetch('select * from ' . tablename('rule') . ' where id=:id limit 1', array(':id' => $this->rule));
11
+
12
+		if (empty($rule)) {
13
+			return false;
14
+		}
15
+
16
+		$names = explode(':', $rule['name']);
17
+		$plugin = isset($names[1]) ? $names[1] : '';
18
+		$processname = $plugin;
19
+
20
+		if (!empty($plugin)) {
21
+			if ($plugin == 'com') {
22
+				$com = isset($names[2]) ? $names[2] : '';
23
+
24
+				if (empty($com)) {
25
+					return false;
26
+				}
27
+
28
+				$processname = $com;
29
+				$processor_file = EWEI_SHOPV2_PROCESSOR . $com . '.php';
30
+			}
31
+			else {
32
+				$processor_file = EWEI_SHOPV2_PLUGIN . $plugin . '/core/processor.php';
33
+			}
34
+
35
+			if (is_file($processor_file)) {
36
+				require $processor_file;
37
+				$processor_class = ucfirst($processname) . 'Processor';
38
+				$proc = new $processor_class($plugin);
39
+
40
+				if (method_exists($proc, 'respond')) {
41
+					return $proc->respond($this);
42
+				}
43
+			}
44
+		}
45
+	}
46
+}
47
+
48
+?>

+ 95 - 0
addons/ewei_shopv2/core/inc/receiver.php Parādīt failu

@@ -0,0 +1,95 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Receiver extends WeModuleReceiver
7
+{
8
+	public function receive()
9
+	{
10
+		global $_W;
11
+		$type = $this->message['type'];
12
+		$event = $this->message['event'];
13
+		if ($event == 'subscribe' && $type == 'subscribe') {
14
+			$this->saleVirtual();
15
+		}
16
+	}
17
+
18
+	public function saleVirtual($obj = NULL)
19
+	{
20
+		global $_W;
21
+
22
+		if (empty($obj)) {
23
+			$obj = $this;
24
+		}
25
+
26
+		$sale = m('common')->getSysset('sale');
27
+		$data = $sale['virtual'];
28
+
29
+		if (empty($data['status'])) {
30
+			return false;
31
+		}
32
+
33
+		load()->model('account');
34
+		$account = account_fetch($_W['uniacid']);
35
+		$open_redis = function_exists('redis') && !is_error(redis());
36
+
37
+		if ($open_redis) {
38
+			$redis_key1 = 'ewei_' . $_W['uniacid'] . '_member_salevirtual_isagent';
39
+			$redis_key2 = 'ewei_' . $_W['uniacid'] . '_member_salevirtual';
40
+			$redis = redis();
41
+
42
+			if (!is_error($redis)) {
43
+				if ($redis->get($redis_key1) != false) {
44
+					$totalagent = $redis->get($redis_key1);
45
+					$totalmember = $redis->get($redis_key2);
46
+				}
47
+				else {
48
+					$totalagent = pdo_fetchcolumn('select count(*) from' . tablename('ewei_shop_member') . ' where uniacid =' . $_W['uniacid'] . ' and isagent =1');
49
+					$totalmember = pdo_fetchcolumn('select count(*) from' . tablename('ewei_shop_member') . ' where uniacid =' . $_W['uniacid']);
50
+					$redis->set($redis_key1, $totalagent, array(0 => 'nx', 'ex' => '3600'));
51
+					$redis->set($redis_key2, $totalmember, array(0 => 'nx', 'ex' => '3600'));
52
+				}
53
+			}
54
+		}
55
+		else {
56
+			$totalagent = pdo_fetchcolumn('select count(*) from' . tablename('ewei_shop_member') . ' where uniacid =' . $_W['uniacid'] . ' and isagent =1');
57
+			$totalmember = pdo_fetchcolumn('select count(*) from' . tablename('ewei_shop_member') . ' where uniacid =' . $_W['uniacid']);
58
+		}
59
+
60
+		$acc = WeAccount::create();
61
+		$member = abs((int) $data['virtual_people']) + (int) $totalmember;
62
+		$commission = abs((int) $data['virtual_commission']) + (int) $totalagent;
63
+		$user = m('member')->checkMemberFromPlatform($obj->message['from'], $acc);
64
+
65
+		if ($_SESSION['eweishop']['poster_member']) {
66
+			$user['isnew'] = true;
67
+			$_SESSION['eweishop']['poster_member'] = NULL;
68
+		}
69
+
70
+		if ($user['isnew']) {
71
+			$message = str_replace('[会员数]', $member, $data['virtual_text']);
72
+			$message = str_replace('[排名]', $member + 1, $message);
73
+		}
74
+		else {
75
+			$message = str_replace('[会员数]', $member, $data['virtual_text2']);
76
+		}
77
+
78
+		$message = str_replace('[分销商数]', $commission, $message);
79
+		$message = str_replace('[昵称]', $user['nickname'], $message);
80
+		$message = htmlspecialchars_decode($message, ENT_QUOTES);
81
+		$message = str_replace('"', '\\"', $message);
82
+		return $this->sendText($acc, $obj->message['from'], $message);
83
+	}
84
+
85
+	public function sendText($acc, $openid, $content)
86
+	{
87
+		$send['touser'] = trim($openid);
88
+		$send['msgtype'] = 'text';
89
+		$send['text'] = array('content' => urlencode($content));
90
+		$data = $acc->sendCustomNotice($send);
91
+		return $data;
92
+	}
93
+}
94
+
95
+?>

+ 284 - 0
addons/ewei_shopv2/core/mobile/account/index.php Parādīt failu

@@ -0,0 +1,284 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Index_EweiShopV2Page extends MobilePage
7
+{
8
+	protected function getWapSet()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$set = m('common')->getSysset(array('shop', 'wap'));
13
+		$set['wap']['color'] = empty($set['wap']['color']) ? '#fff' : $set['wap']['color'];
14
+		$params = array();
15
+
16
+		if (!empty($_GPC['mid'])) {
17
+			$params['mid'] = $_GPC['mid'];
18
+		}
19
+
20
+		if (!empty($_GPC['backurl'])) {
21
+			$params['backurl'] = $_GPC['backurl'];
22
+		}
23
+
24
+		$set['wap']['loginurl'] = mobileUrl('account/login', $params);
25
+		$set['wap']['regurl'] = mobileUrl('account/register', $params);
26
+		$set['wap']['forgeturl'] = mobileUrl('account/forget', $params);
27
+		return $set;
28
+	}
29
+
30
+	public function login()
31
+	{
32
+		global $_W;
33
+		global $_GPC;
34
+		if (is_weixin() || !empty($_GPC['__ewei_shopv2_member_session_' . $_W['uniacid']])) {
35
+			header('location: ' . mobileUrl());
36
+		}
37
+
38
+		if ($_W['ispost']) {
39
+			$mobile = trim($_GPC['mobile']);
40
+			$pwd = trim($_GPC['pwd']);
41
+			$member = pdo_fetch('select id,openid,mobile,pwd,salt from ' . tablename('ewei_shop_member') . ' where mobile=:mobile and mobileverify=1 and uniacid=:uniacid limit 1', array(':mobile' => $mobile, ':uniacid' => $_W['uniacid']));
42
+
43
+			if (empty($member)) {
44
+				show_json(0, '用户不存在');
45
+			}
46
+
47
+			if (md5($pwd . $member['salt']) !== $member['pwd']) {
48
+				show_json(0, '用户或密码错误');
49
+			}
50
+
51
+			m('account')->setLogin($member);
52
+			show_json(1, '登录成功');
53
+		}
54
+
55
+		$set = $this->getWapSet();
56
+		$backurl = '';
57
+
58
+		if (!empty($_GPC['backurl'])) {
59
+			$backurl = $_W['siteroot'] . 'app/index.php?' . base64_decode(urldecode($_GPC['backurl']));
60
+		}
61
+
62
+		$wapset = $_W['shopset']['wap'];
63
+		$sns = $wapset['sns'];
64
+		include $this->template('login', NULL, true);
65
+	}
66
+
67
+	public function register()
68
+	{
69
+		$this->rf(0);
70
+	}
71
+
72
+	public function forget()
73
+	{
74
+		$this->rf(1);
75
+	}
76
+
77
+	protected function rf($type)
78
+	{
79
+		global $_W;
80
+		global $_GPC;
81
+		if (is_weixin() || !empty($_GPC['__ewei_shopv2_member_session_' . $_W['uniacid']])) {
82
+			header('location: ' . mobileUrl());
83
+		}
84
+
85
+		if ($_W['ispost']) {
86
+			$mobile = trim($_GPC['mobile']);
87
+			$verifycode = trim($_GPC['verifycode']);
88
+			$pwd = trim($_GPC['pwd']);
89
+
90
+			if (empty($mobile)) {
91
+				show_json(0, '请输入正确的手机号');
92
+			}
93
+
94
+			if (empty($verifycode)) {
95
+				show_json(0, '请输入验证码');
96
+			}
97
+
98
+			if (empty($pwd)) {
99
+				show_json(0, '请输入密码');
100
+			}
101
+
102
+			$key = '__ewei_shopv2_member_verifycodesession_' . $_W['uniacid'] . '_' . $mobile;
103
+			if (!isset($_SESSION[$key]) || $_SESSION[$key] !== $verifycode || !isset($_SESSION['verifycodesendtime']) || $_SESSION['verifycodesendtime'] + 600 < time()) {
104
+				show_json(0, '验证码错误或已过期!');
105
+			}
106
+
107
+			$member = pdo_fetch('select id,openid,mobile,pwd,salt from ' . tablename('ewei_shop_member') . ' where mobile=:mobile and mobileverify=1 and uniacid=:uniacid limit 1', array(':mobile' => $mobile, ':uniacid' => $_W['uniacid']));
108
+
109
+			if (empty($type)) {
110
+				if (!empty($member)) {
111
+					show_json(0, '此手机号已注册, 请直接登录');
112
+				}
113
+
114
+				$salt = empty($member) ? '' : $member['salt'];
115
+
116
+				if (empty($salt)) {
117
+					$salt = m('account')->getSalt();
118
+				}
119
+
120
+				$openid = empty($member) ? '' : $member['openid'];
121
+				$nickname = empty($member) ? '' : $member['nickname'];
122
+
123
+				if (empty($openid)) {
124
+					$openid = 'wap_user_' . $_W['uniacid'] . '_' . $mobile;
125
+					$nickname = substr($mobile, 0, 3) . 'xxxx' . substr($mobile, 7, 4);
126
+				}
127
+
128
+				$data = array('uniacid' => $_W['uniacid'], 'mobile' => $mobile, 'nickname' => $nickname, 'openid' => $openid, 'pwd' => md5($pwd . $salt), 'salt' => $salt, 'createtime' => time(), 'mobileverify' => 1, 'comefrom' => 'mobile');
129
+			}
130
+			else {
131
+				if (empty($member)) {
132
+					show_json(0, '此手机号未注册');
133
+				}
134
+
135
+				$salt = m('account')->getSalt();
136
+				$data = array('salt' => $salt, 'pwd' => md5($pwd . $salt));
137
+			}
138
+
139
+			if (empty($member)) {
140
+				pdo_insert('ewei_shop_member', $data);
141
+
142
+				if (method_exists(m('member'), 'memberRadisCountDelete')) {
143
+					m('member')->memberRadisCountDelete();
144
+				}
145
+			}
146
+			else {
147
+				pdo_update('ewei_shop_member', $data, array('id' => $member['id']));
148
+			}
149
+
150
+			if (p('commission')) {
151
+				p('commission')->checkAgent($openid);
152
+			}
153
+
154
+			unset($_SESSION[$key]);
155
+			show_json(1, empty($type) ? '注册成功' : '密码重置成功');
156
+		}
157
+
158
+		$sendtime = $_SESSION['verifycodesendtime'];
159
+		if (empty($sendtime) || $sendtime + 60 < time()) {
160
+			$endtime = 0;
161
+		}
162
+		else {
163
+			$endtime = 60 - (time() - $sendtime);
164
+		}
165
+
166
+		$set = $this->getWapSet();
167
+		include $this->template('rf', NULL, true);
168
+	}
169
+
170
+	public function logout()
171
+	{
172
+		global $_W;
173
+		global $_GPC;
174
+		$key = '__ewei_shopv2_member_session_' . $_W['uniacid'];
175
+		isetcookie($key, false, -100);
176
+		header('location: ' . mobileUrl());
177
+		exit();
178
+	}
179
+
180
+	public function sns()
181
+	{
182
+		global $_W;
183
+		global $_GPC;
184
+		if (is_weixin() || !empty($_GPC['__ewei_shopv2_member_session_' . $_W['uniacid']])) {
185
+			header('location: ' . mobileUrl());
186
+		}
187
+
188
+		$sns = trim($_GPC['sns']);
189
+		if ($_W['ispost'] && !empty($sns) && !empty($_GPC['openid'])) {
190
+			m('member')->checkMemberSNS($sns);
191
+		}
192
+
193
+		if ($_GET['openid']) {
194
+			if ($sns == 'qq') {
195
+				$_GET['openid'] = 'sns_qq_' . $_GET['openid'];
196
+			}
197
+
198
+			if ($sns == 'wx') {
199
+				$_GET['openid'] = 'sns_wx_' . $_GET['openid'];
200
+			}
201
+
202
+			m('account')->setLogin($_GET['openid']);
203
+		}
204
+
205
+		$backurl = '';
206
+
207
+		if (!empty($_GPC['backurl'])) {
208
+			$backurl = $_W['siteroot'] . 'app/index.php?' . base64_decode(urldecode($_GPC['backurl']));
209
+		}
210
+
211
+		$backurl = empty($backurl) ? mobileUrl(NULL, NULL, true) : trim($backurl);
212
+		header('location: ' . $backurl);
213
+	}
214
+
215
+	public function verifycode()
216
+	{
217
+		global $_W;
218
+		global $_GPC;
219
+		@session_start();
220
+		$set = $this->getWapSet();
221
+		$mobile = trim($_GPC['mobile']);
222
+		$temp = trim($_GPC['temp']);
223
+		$imgcode = trim($_GPC['imgcode']);
224
+
225
+		if (empty($mobile)) {
226
+			show_json(0, '请输入手机号');
227
+		}
228
+
229
+		if (empty($temp)) {
230
+			show_json(0, '参数错误');
231
+		}
232
+
233
+		if (!empty($_SESSION['verifycodesendtime']) && time() < $_SESSION['verifycodesendtime'] + 60) {
234
+			show_json(0, '请求频繁请稍后重试');
235
+		}
236
+
237
+		if (!empty($set['wap']['smsimgcode'])) {
238
+			if (empty($imgcode)) {
239
+				show_json(0, '请输入图形验证码');
240
+			}
241
+
242
+			$imgcodehash = md5(strtolower($imgcode) . $_W['config']['setting']['authkey']);
243
+
244
+			if ($imgcodehash != trim($_GPC['__code'])) {
245
+				show_json(-1, '请输入正确的图形验证码');
246
+			}
247
+		}
248
+
249
+		$member = pdo_fetch('select id,openid,mobile,pwd,salt from ' . tablename('ewei_shop_member') . ' where mobile=:mobile and mobileverify=1 and uniacid=:uniacid limit 1', array(':mobile' => $mobile, ':uniacid' => $_W['uniacid']));
250
+		if ($temp == 'sms_forget' && empty($member)) {
251
+			show_json(0, '此手机号未注册');
252
+		}
253
+
254
+		if ($temp == 'sms_reg' && !empty($member)) {
255
+			show_json(0, '此手机号已注册,请直接登录');
256
+		}
257
+
258
+		$sms_id = $set['wap'][$temp];
259
+
260
+		if (empty($sms_id)) {
261
+			show_json(0, '短信发送失败(NOSMSID)');
262
+		}
263
+
264
+		$key = '__ewei_shopv2_member_verifycodesession_' . $_W['uniacid'] . '_' . $mobile;
265
+		@session_start();
266
+		$code = random(5, true);
267
+		$shopname = $_W['shopset']['shop']['name'];
268
+		$ret = array('status' => 0, 'message' => '发送失败');
269
+
270
+		if (com('sms')) {
271
+			$ret = com('sms')->send($mobile, $sms_id, array('验证码' => $code, '商城名称' => !empty($shopname) ? $shopname : '商城名称'));
272
+		}
273
+
274
+		if ($ret['status']) {
275
+			$_SESSION[$key] = $code;
276
+			$_SESSION['verifycodesendtime'] = time();
277
+			show_json(1, '短信发送成功');
278
+		}
279
+
280
+		show_json(0, $ret['message']);
281
+	}
282
+}
283
+
284
+?>

+ 33 - 0
addons/ewei_shopv2/core/mobile/goods/code.php Parādīt failu

@@ -0,0 +1,33 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Code_EweiShopV2Page extends MobilePage
7
+{
8
+	public function main()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$openid = $_W['openid'];
13
+		$uniacid = $_W['uniacid'];
14
+		$id = intval($_GPC['id']);
15
+		$goodsid = intval($_GPC['goodsid']);
16
+		$codegoods = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_goodscode_good') . " WHERE\r\n            uniacid = " . $uniacid . ' and goodsid = ' . $goodsid . ' and id = ' . $id . ' and status = 1 ');
17
+
18
+		if (empty($codegoods)) {
19
+			$this->message(array('message' => '该商品不存在或已删除'), mobileUrl(''), 'error');
20
+		}
21
+
22
+		$goods = pdo_fetch('SELECT title,content FROM ' . tablename('ewei_shop_goods') . " WHERE\r\n            uniacid = " . $uniacid . ' and id = ' . $goodsid . ' and deleted=0 and status = 1 ');
23
+
24
+		if (empty($goods)) {
25
+			$this->message(array('message' => '该商品不存在或已删除'), mobileUrl(''), 'error');
26
+		}
27
+
28
+		$goods['content'] = m('ui')->lazy($goods['content']);
29
+		include $this->template();
30
+	}
31
+}
32
+
33
+?>

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1978 - 0
addons/ewei_shopv2/core/mobile/goods/detail.php


+ 117 - 0
addons/ewei_shopv2/core/mobile/goods/index.php Parādīt failu

@@ -0,0 +1,117 @@
1
+<?php
2
+
3
+if (!defined('IN_IA')) {
4
+	exit('Access Denied');
5
+}
6
+
7
+class Index_EweiShopV2Page extends MobilePage {
8
+
9
+	function main() {
10
+		global $_W, $_GPC;
11
+
12
+		$allcategory = m('shop')->getCategory();
13
+		$catlevel = intval($_W['shopset']['category']['level']);
14
+		$opencategory = true; //是否自己商品不同步分类
15
+		$plugin_commission = p('commission');
16
+		if ($plugin_commission && intval($_W['shopset']['commission']['level']) > 0) {
17
+			$mid = intval($_GPC['mid']);
18
+			if (!empty($mid) && empty($_W['shopset']['commission']['closemyshop']) && !empty($_W['shopset']['commission']['select_goods'])) {
19
+				$shop = p('commission')->getShop($mid);
20
+				if (empty($shop['selectcategory']) && !empty($shop['selectgoods'])) {
21
+					$opencategory = false;
22
+				}
23
+			}
24
+		}
25
+
26
+		include $this->template();
27
+	}
28
+	function gift(){
29
+		global $_W,$_GPC;
30
+		$uniacid = $_W['uniacid'];
31
+		$giftid = intval($_GPC['id']);
32
+
33
+		$gift = pdo_fetch("select * from ".tablename('ewei_shop_gift')." where uniacid = ".$uniacid." and id = ".$giftid." and starttime <= ".time()." and endtime >= ".time()." and status = 1 ");
34
+		$giftgoodsid = explode(",",$gift['giftgoodsid']);
35
+		$giftgoods = array();
36
+		if(!empty($giftgoodsid)){
37
+			foreach($giftgoodsid as $key => $value){
38
+				$giftgoods[$key] = pdo_fetch("select id,status,title,thumb,marketprice,total from ".tablename('ewei_shop_goods')." where uniacid = ".$uniacid." and deleted = 0  and id = ".$value." and status = 2 ");
39
+			}
40
+			$giftgoods = array_filter($giftgoods);
41
+		}
42
+
43
+		include $this->template();
44
+	}
45
+
46
+	function get_list() {
47
+
48
+
49
+		global $_GPC, $_W;
50
+
51
+		$args = array(
52
+			'pagesize' => 10,
53
+			'page' => intval($_GPC['page']),
54
+			'isnew' => trim($_GPC['isnew']),
55
+			'ishot' => trim($_GPC['ishot']),
56
+			'isrecommand' => trim($_GPC['isrecommand']),
57
+			'isdiscount' => trim($_GPC['isdiscount']),
58
+			'istime' => trim($_GPC['istime']),
59
+			'issendfree' => trim($_GPC['issendfree']),
60
+			'keywords' => trim($_GPC['keywords']),
61
+			'cate' => trim($_GPC['cate']),
62
+			'order' => trim($_GPC['order']),
63
+			'by' => trim($_GPC['by'])
64
+		);
65
+		
66
+		//判断是否开启自选商品
67
+		$plugin_commission = p('commission');
68
+		if ($plugin_commission && intval($_W['shopset']['commission']['level'])>0 && empty($_W['shopset']['commission']['closemyshop']) && !empty($_W['shopset']['commission']['select_goods'])) {
69
+            $frommyshop = intval($_GPC['frommyshop']);
70
+			$mid = intval($_GPC['mid']);
71
+			if (!empty($mid) && !empty($frommyshop)) {
72
+				$shop = p('commission')->getShop($mid);
73
+				if (!empty($shop['selectgoods'])) {
74
+					$args['ids'] = $shop['goodsids'];
75
+				}
76
+			}
77
+		}
78
+		$this->_condition($args);
79
+	}
80
+
81
+	function query() {
82
+		global $_GPC, $_W;
83
+		$args = array(
84
+			'pagesize' => 10,
85
+			'page' => intval($_GPC['page']),
86
+			'isnew' => trim($_GPC['isnew']),
87
+			'ishot' => trim($_GPC['ishot']),
88
+			'isrecommand' => trim($_GPC['isrecommand']),
89
+			'isdiscount' => trim($_GPC['isdiscount']),
90
+			'istime' => trim($_GPC['istime']),
91
+			'keywords' => trim($_GPC['keywords']),
92
+			'cate' => trim($_GPC['cate']),
93
+			'order' => trim($_GPC['order']),
94
+			'by' => trim($_GPC['by'])
95
+		);
96
+		$this->_condition($args);
97
+	}
98
+
99
+	private function _condition($args)
100
+	{
101
+		global $_GPC;
102
+		$merch_plugin = p('merch');
103
+		$merch_data = m('common')->getPluginset('merch');
104
+		if ($merch_plugin && $merch_data['is_openmerch']) {
105
+			$args['merchid'] = intval($_GPC['merchid']);
106
+		}
107
+
108
+		if (isset($_GPC['nocommission'])) {
109
+			$args['nocommission'] = intval($_GPC['nocommission']);
110
+		}
111
+
112
+		$goods = m('goods')->getList($args);
113
+
114
+		show_json(1, array('list' => $goods['list'], 'total' => $goods['total'], 'pagesize' => $args['pagesize']));
115
+	}
116
+
117
+}

+ 98 - 0
addons/ewei_shopv2/core/mobile/goods/package.php Parādīt failu

@@ -0,0 +1,98 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Package_EweiShopV2Page extends MobilePage
7
+{
8
+	public function main()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$openid = $_W['openid'];
13
+		$uniacid = $_W['uniacid'];
14
+		$goodsid = intval($_GPC['goodsid']);
15
+		$packages_goods = array();
16
+		$packages = array();
17
+		$goodsid_array = array();
18
+
19
+		if ($goodsid) {
20
+			$packages_goods = pdo_fetchall('SELECT id,pid FROM ' . tablename('ewei_shop_package_goods') . "\r\n                    WHERE uniacid = " . $uniacid . ' and goodsid = ' . $goodsid . ' group by pid  ORDER BY id DESC');
21
+
22
+			foreach ($packages_goods as $key => $value) {
23
+				$packages[$key] = pdo_fetch('SELECT id,title,thumb,price,goodsid FROM ' . tablename('ewei_shop_package') . "\r\n                    WHERE uniacid = " . $uniacid . ' and id = ' . $value['pid'] . ' and starttime <= ' . time() . ' and endtime >= ' . time() . ' and deleted = 0 and status = 1  ORDER BY id DESC');
24
+			}
25
+
26
+			$packages = array_values(array_filter($packages));
27
+		}
28
+		else {
29
+			$packages = pdo_fetchall('SELECT id,title,thumb,price,goodsid FROM ' . tablename('ewei_shop_package') . "\r\n                    WHERE uniacid = " . $uniacid . ' and starttime <= ' . time() . ' and endtime >= ' . time() . ' and deleted = 0 and status = 1 ORDER BY id DESC');
30
+		}
31
+
32
+		if (empty($packages)) {
33
+			$this->message('套餐不存在或已删除!', mobileUrl(), 'error');
34
+		}
35
+
36
+		foreach ($packages as $key => $value) {
37
+			$goods = explode(',', $value['goodsid']);
38
+
39
+			foreach ($goods as $k => $val) {
40
+				$g = pdo_fetch('SELECT id,marketprice FROM ' . tablename('ewei_shop_goods') . "\r\n                    WHERE uniacid = " . $uniacid . ' and id = ' . $val . '  ORDER BY id DESC');
41
+				$goods['goodsprice'] += $g['marketprice'];
42
+			}
43
+
44
+			$packages[$key]['goodsprice'] = $goods['goodsprice'];
45
+		}
46
+
47
+		$packages = set_medias($packages, array('thumb'));
48
+		include $this->template();
49
+	}
50
+
51
+	public function detail()
52
+	{
53
+		global $_W;
54
+		global $_GPC;
55
+		$uniacid = $_W['uniacid'];
56
+		$pid = intval($_GPC['pid']);
57
+		$package = pdo_fetch('SELECT id,title,price,freight,share_title,share_icon,share_desc FROM ' . tablename('ewei_shop_package') . "\r\n                    WHERE uniacid = " . $uniacid . ' and id = ' . $pid . ' ');
58
+		$packgoods = array();
59
+		$packgoods = pdo_fetchall('SELECT id,title,thumb,marketprice,packageprice,`option`,goodsid FROM ' . tablename('ewei_shop_package_goods') . "\r\n                    WHERE uniacid = " . $uniacid . ' and pid = ' . $pid . '  ORDER BY id DESC');
60
+		$packgoods = set_medias($packgoods, array('thumb'));
61
+		$option = array();
62
+
63
+		foreach ($packgoods as $key => $value) {
64
+			$option_array = array();
65
+			$option_array = explode(',', $value['option']);
66
+
67
+			if (0 < $option_array[0]) {
68
+				$pgo = pdo_fetch('SELECT id,title,packageprice FROM ' . tablename('ewei_shop_package_goods_option') . "\r\n                    WHERE uniacid = " . $uniacid . ' and pid = ' . $pid . ' and goodsid = ' . $value['goodsid'] . ' and optionid = ' . $option_array[0] . ' ');
69
+				$packgoods[$key]['packageprice'] = $pgo['packageprice'];
70
+			}
71
+		}
72
+
73
+		$_W['shopshare'] = array('title' => !empty($package['share_title']) ? $package['share_title'] : $package['title'], 'imgUrl' => !empty($package['share_icon']) ? tomedia($package['share_icon']) : tomedia($package['thumb']), 'desc' => !empty($package['share_desc']) ? $package['share_desc'] : $_W['shopset']['shop']['name'], 'link' => mobileUrl('goods/package/detail', array('pid' => $package['id']), true));
74
+		include $this->template('goods/packdetail');
75
+	}
76
+
77
+	public function option()
78
+	{
79
+		global $_W;
80
+		global $_GPC;
81
+		$openid = $_W['openid'];
82
+		$uniacid = intval($_W['uniacid']);
83
+		$pid = intval($_GPC['pid']);
84
+		$goodsid = intval($_GPC['goodsid']);
85
+		$optionid = array();
86
+		$option = array();
87
+		$packgoods = pdo_fetch('SELECT id,title,`option` FROM ' . tablename('ewei_shop_package_goods') . "\r\n                    WHERE pid = :pid and goodsid = :goodsid and uniacid = :uniacid  ORDER BY id DESC", array(':pid' => $pid, ':goodsid' => $goodsid, ':uniacid' => $uniacid));
88
+		$optionid = explode(',', $packgoods['option']);
89
+
90
+		foreach ($optionid as $key => $value) {
91
+			$option[$key] = pdo_fetch('SELECT id,title,packageprice,optionid,goodsid FROM ' . tablename('ewei_shop_package_goods_option') . "\r\n                    WHERE pid = :pid and goodsid = :goodsid and uniacid = :uniacid and optionid = :optionid ORDER BY id DESC", array(':goodsid' => $goodsid, ':optionid' => intval($value), ':uniacid' => $uniacid, ':pid' => $pid));
92
+		}
93
+
94
+		show_json(1, $option);
95
+	}
96
+}
97
+
98
+?>

+ 557 - 0
addons/ewei_shopv2/core/mobile/goods/picker.php Parādīt failu

@@ -0,0 +1,557 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+    exit('Access Denied');
4
+}
5
+
6
+class Picker_EweiShopV2Page extends MobilePage {
7
+
8
+    function main()
9
+    {
10
+        global $_W, $_GPC;
11
+        $id = intval($_GPC['id']);
12
+        $action = trim($_GPC['action']);
13
+        $rank = intval($_SESSION[$id . '_rank']);
14
+        $log_id = intval($_SESSION[$id . '_log_id']);
15
+        $join_id = intval($_SESSION[$id . '_join_id']);
16
+
17
+        $cremind = false;
18
+        $seckillinfo = false;
19
+        $seckill  = p('seckill');
20
+        if( $seckill){
21
+            $time = time();
22
+            $seckillinfo = $seckill->getSeckill($id);
23
+
24
+            if(!empty($seckillinfo)){
25
+                if($time >= $seckillinfo['starttime'] && $time<$seckillinfo['endtime']){
26
+                    $seckillinfo['status'] = 0;
27
+                }elseif( $time < $seckillinfo['starttime'] ){
28
+                    $seckillinfo['status'] = 1;
29
+                }else {
30
+                    $seckillinfo['status'] = -1;
31
+                }
32
+            }
33
+        }
34
+
35
+        /* 直播间商品 处理Step.1 */
36
+        $liveid = intval($_GPC['liveid']);
37
+        if(!empty($liveid)){
38
+            $isliving=false;
39
+            if(p('live')){
40
+                $isliving = p('live')->isLiving($liveid);
41
+            }
42
+            if(!$isliving){
43
+                $liveid = 0;
44
+            }
45
+        }
46
+
47
+
48
+        //商品
49
+        $goods = pdo_fetch('select id,thumb,title,marketprice,total,maxbuy,minbuy,unit,hasoption,showtotal,diyformid,diyformtype,diyfields,isdiscount,presellprice,isdiscount_time,isdiscount_discounts,hascommission,nocommission,commission,commission1_rate,marketprice,commission1_pay,needfollow, followtip, followurl, `type`, isverify, maxprice, minprice, merchsale,ispresell,preselltimeend,unite_total,
50
+                threen,preselltimestart,presellovertime,presellover,islive,liveprice,minliveprice,maxliveprice
51
+                from ' . tablename('ewei_shop_goods') . ' where id=:id and uniacid=:uniacid limit 1', array(':id' => $id, ':uniacid' => $_W['uniacid']));
52
+        if (empty($goods)) {
53
+            show_json(0);
54
+        }
55
+
56
+        $threenprice = json_decode($goods['threen'],1);
57
+        $goods['thistime'] = time();
58
+        $goods = set_medias($goods, 'thumb');
59
+
60
+
61
+        /* 直播间商品 处理Step.2 */
62
+        if(!empty($liveid)){
63
+            $islive =false;
64
+            if(p('live')){
65
+                $islive = p('live')->getLivePrice($goods, $liveid);
66
+            }
67
+            if($islive){
68
+                $goods['minprice'] = $islive['minprice'];
69
+                $goods['maxprice'] = $islive['maxprice'];
70
+            }
71
+        }
72
+
73
+
74
+        $openid = $_W['openid'];
75
+
76
+        if (is_weixin()) {
77
+            $follow = m("user")->followed($openid);
78
+            if (!empty($goods['needfollow']) && !$follow) {
79
+                $followtip = empty($goods['followtip']) ? "如果您想要购买此商品,需要您关注我们的公众号,点击【确定】关注后再来购买吧~" : $goods['followtip'];
80
+                $followurl = empty($goods['followurl']) ? $_W['shopset']['share']['followurl'] : $goods['followurl'];
81
+                show_json(2, array('followtip' => $followtip, 'followurl' => $followurl));
82
+            }
83
+        }
84
+
85
+
86
+        $openid =$_W['openid'];
87
+        $member = m('member')->getMember($openid);
88
+
89
+        //  验证是否登录
90
+        if(empty($openid)){
91
+            $sendtime = $_SESSION['verifycodesendtime'];
92
+            if(empty($sendtime) || $sendtime+60<time()){
93
+                $endtime = 0;
94
+            }else{
95
+                $endtime = 60 - (time() - $sendtime);
96
+            }
97
+            show_json(4, array(
98
+                'endtime'=>$endtime,
99
+                'imgcode'=>$_W['shopset']['wap']['smsimgcode']
100
+            ));
101
+        }
102
+
103
+        //  验证手机号
104
+        if(!empty($_W['shopset']['wap']['open']) && !empty($_W['shopset']['wap']['mustbind']) && empty($member['mobileverify'])){
105
+            $sendtime = $_SESSION['verifycodesendtime'];
106
+            if(empty($sendtime) || $sendtime+60<time()){
107
+                $endtime = 0;
108
+            }else{
109
+                $endtime = 60 - (time() - $sendtime);
110
+            }
111
+            show_json(3, array(
112
+                'endtime'=>$endtime,
113
+                'imgcode'=>$_W['shopset']['wap']['smsimgcode']
114
+            ));
115
+        }
116
+        //预售
117
+        if($goods['ispresell'] > 0){
118
+            $times = $goods['presellovertime'] * 60 * 60 * 24 + $goods['preselltimeend'];
119
+            if(!($goods['presellover']>0 && $times <= time())){
120
+                if($goods['preselltimestart'] > 0 && $goods['preselltimestart'] > time()){
121
+                    show_json(5,'预售未开始');
122
+                }
123
+                if($goods['preselltimeend'] > 0 && $goods['preselltimeend'] < time()){
124
+                    show_json(5,'预售已结束');
125
+                }
126
+            }
127
+
128
+            //预售结束转为正常销售
129
+            /*$times = $goods['presellovertime'] * 60 * 60 * 24 + $goods['preselltimeend'];
130
+            if($goods['presellover']>0 && $times <= time() && $goods['preselltimeend'] > 0 && $goods['preselltimeend'] < time()){
131
+
132
+            }else{
133
+                show_json(5,'预售已结束');
134
+            }*/
135
+        }
136
+
137
+
138
+        if($goods['isdiscount'] && $goods['isdiscount_time']>=time()){
139
+            //有促销
140
+            $isdiscount = true;
141
+            $isdiscount_discounts = json_decode($goods['isdiscount_discounts'],true);
142
+            $levelid = $member['level'];
143
+            $key = empty($levelid)?'default':'level'.$levelid;
144
+        } else {
145
+            $isdiscount = false;
146
+        }
147
+
148
+        //任务活动购买商品
149
+        $task_goods_data = m('goods')->getTaskGoods($openid, $id, $rank, $log_id, $join_id);
150
+        if (empty($task_goods_data['is_task_goods'])) {
151
+            $is_task_goods = 0;
152
+        } else {
153
+            $is_task_goods = $task_goods_data['is_task_goods'];
154
+            $is_task_goods_option = $task_goods_data['is_task_goods_option'];
155
+            $task_goods = $task_goods_data['task_goods'];
156
+        }
157
+
158
+        $specs =false;
159
+        $options = false;
160
+        if (!empty($goods) && $goods['hasoption']) {
161
+            $specs = pdo_fetchall('select * from ' . tablename('ewei_shop_goods_spec') . ' where goodsid=:goodsid and uniacid=:uniacid order by displayorder asc', array(':goodsid' => $id, ':uniacid' => $_W['uniacid']));
162
+            foreach($specs as &$spec) {
163
+                $spec['items'] = pdo_fetchall('select * from '.tablename('ewei_shop_goods_spec_item')." where specid=:specid and `show`=1 order by displayorder asc",array(':specid'=>$spec['id']));
164
+            }
165
+            unset($spec);
166
+            $options = pdo_fetchall('select * from ' . tablename('ewei_shop_goods_option') . ' where goodsid=:goodsid and uniacid=:uniacid order by displayorder asc', array(':goodsid' => $id, ':uniacid' => $_W['uniacid']));
167
+        }
168
+
169
+        if (!empty($options) && !empty($goods['unite_total'])) {
170
+            foreach($options as &$option){
171
+                $option['stock'] = $goods['total'];
172
+            }
173
+            unset($option);
174
+        }
175
+
176
+        /* 直播间商品 处理Step.3 */
177
+        if(!empty($liveid) && !empty($options)){
178
+            // 重新获取直播商品规格价格
179
+            //$options =array();
180
+            if(p('live')){
181
+                $options = p('live')->getLiveOptions($goods['id'], $liveid, $options);
182
+            }
183
+            $prices = array();
184
+            foreach ($options as $option){
185
+                $prices[] = price_format($option['marketprice']);
186
+            }
187
+            unset($option);
188
+
189
+            $goods['minprice'] = min($prices);
190
+            $goods['maxprice'] = max($prices);
191
+        }
192
+
193
+        if( $seckillinfo && $seckillinfo['status']==0){
194
+            $minprice = $maxprice = $goods['marketprice'] = $seckillinfo['price'];
195
+            if(count($seckillinfo['options'])>0 && !empty($options)){
196
+                foreach($options as &$option){
197
+                    foreach($seckillinfo['options'] as $so){
198
+                        if($option['id']==$so['optionid']){
199
+                            $option['marketprice'] = $so['price'];
200
+                        }
201
+                    }
202
+                }
203
+                unset($option);
204
+            }
205
+        } else{
206
+            $minprice = $goods['minprice'];
207
+            $maxprice = $goods['maxprice'] ;
208
+        }
209
+
210
+        //价格显示
211
+        if (!empty($is_task_goods)) {
212
+            if ( isset($options) && count($options) > 0 && $goods['hasoption']) {
213
+                $prices = array();
214
+                foreach ($task_goods['spec'] as $k => $v) {
215
+                    $prices[] = $v['marketprice'];
216
+                }
217
+                $minprice = min($prices);
218
+                $maxprice = max($prices);
219
+
220
+                foreach ($options as $k => $v) {
221
+                    $option_id = $v['id'];
222
+                    if (array_key_exists($option_id, $task_goods['spec'])) {
223
+                        if($goods['ispresell']>0 && ($goods['preselltimeend'] == 0 || $goods['preselltimeend'] > time())){
224
+                            $options[$k]['marketprice'] = $task_goods['spec'][$option_id]['presellprice'];
225
+                        }else{
226
+                            $options[$k]['marketprice'] = $task_goods['spec'][$option_id]['marketprice'];
227
+                        }
228
+                        $options[$k]['stock'] = $task_goods['spec'][$option_id]['total'];
229
+                    }
230
+                    $prices[] = $v['marketprice'];
231
+                }
232
+
233
+            } else {
234
+                $minprice = $task_goods['marketprice'];
235
+                $maxprice = $task_goods['marketprice'];
236
+            }
237
+
238
+        } else {
239
+            if($goods['isdiscount'] && $goods['isdiscount_time']>=time()){
240
+                $goods['oldmaxprice'] = $maxprice;
241
+                $isdiscount_discounts = json_decode($goods['isdiscount_discounts'],true);
242
+                $prices = array();
243
+
244
+                if (!isset($isdiscount_discounts['type']) || empty($isdiscount_discounts['type'])) {
245
+                    //统一促销
246
+                    $level = m('member')->getLevel($openid);
247
+                    $prices_array = m('order')->getGoodsDiscountPrice($goods, $level, 1);
248
+                    $prices[] = $prices_array['price'];
249
+                } else {
250
+                    //详细促销
251
+                    $goods_discounts = m('order')->getGoodsDiscounts($goods, $isdiscount_discounts, $levelid, $options);
252
+                    $prices = $goods_discounts['prices'];
253
+                    $options = $goods_discounts['options'];
254
+                }
255
+
256
+                $minprice = min($prices);
257
+                $maxprice = max($prices);
258
+            }
259
+        }
260
+
261
+//        获取不同规格的不同佣金
262
+        $clevel = $this->getcLevel($_W['openid']);
263
+        $set = array();
264
+        if(p('commission')) {
265
+            $set = $this->getSet();
266
+            $goods['cansee'] = $set['cansee'];
267
+            $goods['seetitle'] = $set['seetitle'];
268
+        }else{
269
+            $goods['cansee'] = 0;
270
+            $goods['seetitle'] = '';
271
+        }
272
+        if(p('seckill')){
273
+            if(!p('seckill')->getSeckill($goods['id'])){
274
+//                    秒杀
275
+
276
+
277
+        if($goods['nocommission'] ==1){
278
+            $seecommission = 0;
279
+        }else if($goods['hascommission'] == 1 && $goods['nocommission'] ==0){
280
+
281
+            $price = $goods['maxprice'];
282
+            $levelid = 'default';
283
+            if($clevel == 'false'){
284
+                $seecommission = 0;
285
+            }else {
286
+                if($clevel) {
287
+                    $levelid = 'level' . $clevel['id'];
288
+                }
289
+                $goods_commission = !empty($goods['commission']) ? json_decode($goods['commission'], true) : '';
290
+                if($goods_commission['type'] == 0) {
291
+                    $seecommission = $set['level'] >= 1 ? ($goods['commission1_rate'] > 0 ? ($goods['commission1_rate'] * $goods['marketprice'] / 100) : $goods['commission1_pay']) : 0;
292
+                    if(is_array($options) && !empty($options)){
293
+                        foreach ($options as $k => $v) {
294
+                            $seecommission = $set['level'] >= 1 ? ($goods['commission1_rate'] > 0 ? ($goods['commission1_rate'] * $v['marketprice'] / 100) : $v['commission1_pay']) : 0;
295
+                            $options[$k]['seecommission'] = $seecommission;
296
+                        }
297
+                    }
298
+                } else {
299
+                    //获取每个规格的佣金
300
+                    if(is_array($options)) {
301
+                        foreach ($goods_commission[$levelid] as $key => $value) {
302
+                            foreach ($options as $k => $v) {
303
+                                if(('option' . $v['id']) == $key) {
304
+                                    if(strexists($value[0], '%')) {
305
+                                        $options[$k]['seecommission'] = (floatval(str_replace('%', '', $value[0]) / 100) * $v['marketprice']);
306
+                                        continue;
307
+                                    } else {
308
+                                        $options[$k]['seecommission'] = $value[0];
309
+                                        continue;
310
+                                    }
311
+                                }
312
+                            }
313
+                        }
314
+                    }
315
+                }
316
+            }
317
+        }elseif($goods['hasoption'] ==1&&$goods['hascommission'] == 0 && $goods['nocommission'] ==0){
318
+            foreach($options as $ke=>$vl){
319
+                if ($clevel!='false' && $clevel) {
320
+                    $options[$ke]['seecommission'] = $set['level'] >= 1 ? round($clevel['commission1'] * $vl['marketprice'] / 100, 2) : 0;
321
+                } else {
322
+                    $options[$ke]['seecommission'] = $set['level'] >= 1 ? round($set['commission1'] * $vl['marketprice'] / 100, 2) : 0;
323
+                }
324
+            }
325
+        }else{
326
+            if ($clevel!='false' && $clevel) {
327
+                $seecommission = $set['level'] >= 1 ? round($clevel['commission1'] * $goods['marketprice'] / 100, 2) : 0;
328
+            } else {
329
+                $seecommission = $set['level'] >= 1 ? round($set['commission1'] * $goods['marketprice'] / 100, 2) : 0;
330
+            }
331
+        }
332
+            }
333
+        }
334
+
335
+        if($goods['ispresell']>0 && ($goods['preselltimeend'] == 0 || $goods['preselltimeend'] > time())){
336
+            $presell = pdo_fetch("select min(presellprice) as minprice,max(presellprice) as maxprice from ".tablename('ewei_shop_goods_option')." where goodsid = ".$id);
337
+            $minprice = $presell['minprice'];
338
+            $maxprice = $presell['maxprice'];
339
+        }
340
+
341
+
342
+        $goods['minprice'] = number_format( $minprice,2); $goods['maxprice'] =number_format(  $maxprice,2);
343
+
344
+        $diyformhtml = "";
345
+        if ($action == 'cremind') {
346
+            $cremind_plugin = p('cremind');
347
+            $cremind_data = m('common')->getPluginset('cremind');
348
+            if ($cremind_plugin && $cremind_data['remindopen']) {
349
+                $cremind = true;
350
+            }
351
+
352
+            ob_start();
353
+            include $this->template('cremind/formfields');
354
+            $cremindformhtml = ob_get_contents();
355
+            ob_clean();
356
+        } else {
357
+            //自定义表单
358
+            $diyform_plugin = p('diyform');
359
+            if($diyform_plugin){
360
+                $fields = false;
361
+
362
+                if($goods['diyformtype'] == 1){
363
+
364
+                    //模板
365
+                    if(!empty($goods['diyformid'])){
366
+                        $diyformid = $goods['diyformid'];
367
+                        $formInfo = $diyform_plugin->getDiyformInfo($diyformid);
368
+                        $fields = $formInfo['fields'];
369
+                    }
370
+                } else if($goods['diyformtype'] == 2){
371
+                    //自定义
372
+                    $diyformid = 0;
373
+                    $fields = iunserializer($goods['diyfields']);
374
+                    if(empty($fields)){
375
+                        $fields = false;
376
+                    }
377
+                }
378
+
379
+                if(!empty($fields)){
380
+                    ob_start();
381
+                    $inPicker = true;
382
+
383
+                    $openid = $_W['openid'];
384
+                    $member = m('member')->getMember($openid, true);
385
+                    $f_data = $diyform_plugin->getLastData(3, 0, $diyformid, $id, $fields, $member);
386
+
387
+                    $flag = 0;
388
+                    if (!empty($f_data)) {
389
+                        foreach ($f_data as $k => $v) {
390
+                            if (!empty($v)) {
391
+                                $flag = 1;
392
+                                break;
393
+                            }
394
+                        }
395
+                    }
396
+
397
+                    if (empty($flag)) {
398
+                        $f_data = $diyform_plugin->getLastCartData($id);
399
+                    }
400
+
401
+                    $area_set = m('util')->get_area_config_set();
402
+                    $new_area = intval($area_set['new_area']);
403
+                    $address_street = intval($area_set['address_street']);
404
+
405
+                    include $this->template('diyform/formfields');
406
+                    $diyformhtml = ob_get_contents();
407
+                    ob_clean();
408
+                }
409
+            }
410
+        }
411
+
412
+
413
+        if (!empty($specs))
414
+        {
415
+            foreach ($specs as $key => $value)
416
+            {
417
+                foreach ($specs[$key]['items'] as $k=>&$v)
418
+                {
419
+                    $v['thumb'] = tomedia($v['thumb']);
420
+                }
421
+            }
422
+        }
423
+        //是否可以加入购物车
424
+        $goods['canAddCart'] = true;
425
+        if ($goods['isverify'] == 2 || $goods['type'] == 2 || $goods['type'] == 3 || $goods['type'] == 20 || !empty($goods['cannotrefund'])) {
426
+            $goods['canAddCart'] = false;
427
+        }
428
+
429
+
430
+        if (p('task')){
431
+            $task_id = intval($_SESSION[$id . '_task_id']);
432
+            if (!empty($task_id)){
433
+                $rewarded = pdo_fetchcolumn("SELECT `rewarded` FROM ".tablename('ewei_shop_task_extension_join')." WHERE id = :id AND uniacid = :uniacid",array(':id'=>$task_id,':uniacid'=>$_W['uniacid']));
434
+                $taskGoodsInfo = unserialize($rewarded);
435
+                $taskGoodsInfo = $taskGoodsInfo['goods'][$id];
436
+                if (empty($taskGoodsInfo['option'])){
437
+                    $goods['marketprice'] = $taskGoodsInfo['price'];
438
+                }else{//有规格
439
+                    foreach($options as $gk =>$gv){
440
+                        if ($options[$gk]['id'] == $taskGoodsInfo){
441
+                            $options[$gk]['marketprice'] = $taskGoodsInfo['price'];
442
+                        }
443
+                    }
444
+                }
445
+            }
446
+        }
447
+
448
+        //赠品
449
+        $sale_plugin = com('sale');
450
+        $giftid = 0;
451
+        $goods['cangift']  = false;
452
+        $gifttitle = '';
453
+        if($sale_plugin){
454
+            $giftinfo = array();
455
+            $isgift = 0;
456
+            $gifts = array();
457
+            $giftgoods = array();
458
+            $gifts = pdo_fetchall("select id,goodsid,giftgoodsid,thumb,title from ".tablename('ewei_shop_gift')." where uniacid = ".$_W['uniacid']." and activity = 2 and status = 1 and starttime <= ".time()." and endtime >= ".time()."  ");
459
+            foreach($gifts as $key => &$value){
460
+                $gid = explode(",",$value['goodsid']);
461
+                foreach ($gid as $ke => $val){
462
+                    if($val==$id){
463
+                        $giftgoods = explode(",",$value['giftgoodsid']);
464
+                        foreach($giftgoods as $k => $val){
465
+                            $giftdata = pdo_fetch("select id,title,thumb,marketprice,total from ".tablename('ewei_shop_goods')." where uniacid = ".$_W['uniacid']." and deleted = 0 and total > 0 and status = 2 and id = ".$val." ");
466
+                            if(!empty($giftdata)){
467
+                                $isgift = 1;
468
+                                $gifts[$key]['gift'][$k] = $giftdata;
469
+                                $gifts[$key]['gift'][$k]['thumb'] = tomedia( $gifts[$key]['gift'][$k]['thumb']);
470
+                                $gifttitle = !empty($value['gift'][$k]['title']) ? $value['gift'][$k]['title'] : '赠品';
471
+                            }
472
+                        }
473
+                    }
474
+                }
475
+                if(empty($value['gift'])){
476
+                    unset($gifts[$key]);
477
+                }
478
+            }
479
+            if($isgift){
480
+                if($_GPC['cangift']){
481
+                    $goods['cangift'] = true;
482
+                }
483
+                $gifts = array_values($gifts);
484
+                $giftid = $gifts[0]['id'];
485
+                $giftinfo = $gifts;
486
+            }
487
+        }
488
+        $goods['giftid'] = $giftid;
489
+        $goods['giftinfo'] = $giftinfo;
490
+        $goods['gifttitle'] = $gifttitle;
491
+        $goods['gifttotal'] = count($goods['giftinfo']);
492
+        show_json(1, array(
493
+            'goods' => $goods,
494
+            'seckillinfo'=>$seckillinfo,
495
+            'specs' => $specs,
496
+            'options' => $options,
497
+            'diyformhtml'=>$diyformhtml,
498
+            'cremind'=>$cremind,
499
+            'cremindformhtml'=>$cremindformhtml
500
+        ));
501
+    }
502
+//获取分销商等级
503
+    function getcLevel($openid)
504
+    {
505
+        global $_W;
506
+        $level = 'false';
507
+        if (empty($openid)) {
508
+            return $level;
509
+        }
510
+        $member = m('member')->getMember($openid);
511
+        if (empty($member['isagent']) || $member['status']==0 || $member['agentblack'] ==1) {
512
+
513
+            return $level;
514
+        }
515
+
516
+        $level = pdo_fetch('select * from ' . tablename('ewei_shop_commission_level') . ' where uniacid=:uniacid and id=:id limit 1', array(':uniacid' => $_W['uniacid'], ':id' => $member['agentlevel']));
517
+
518
+        return $level;
519
+    }
520
+
521
+    function getSet()
522
+    {
523
+        $set = m('common')->getPluginset('commission');
524
+
525
+        $set['texts'] = array(
526
+            'agent' => empty($set['texts']['agent']) ? '分销商' : $set['texts']['agent'],
527
+            'shop' => empty($set['texts']['shop']) ? '小店' : $set['texts']['shop'],
528
+            'myshop' => empty($set['texts']['myshop']) ? '我的小店' : $set['texts']['myshop'],
529
+            'center' => empty($set['texts']['center']) ? '分销中心' : $set['texts']['center'],
530
+            'become' => empty($set['texts']['become']) ? '成为分销商' : $set['texts']['become'],
531
+            'withdraw' => empty($set['texts']['withdraw']) ? '提现' : $set['texts']['withdraw'],
532
+            'commission' => empty($set['texts']['commission']) ? '佣金' : $set['texts']['commission'],
533
+            'commission1' => empty($set['texts']['commission1']) ? '分销佣金' : $set['texts']['commission1'],
534
+            'commission_total' => empty($set['texts']['commission_total']) ? '累计佣金' : $set['texts']['commission_total'],
535
+            'commission_ok' => empty($set['texts']['commission_ok']) ? '可提现佣金' : $set['texts']['commission_ok'],
536
+            'commission_apply' => empty($set['texts']['commission_apply']) ? '已申请佣金' : $set['texts']['commission_apply'],
537
+            'commission_check' => empty($set['texts']['commission_check']) ? '待打款佣金' : $set['texts']['commission_check'],
538
+            'commission_lock' => empty($set['texts']['commission_lock']) ? '未结算佣金' : $set['texts']['commission_lock'],
539
+            'commission_detail' => empty($set['texts']['commission_detail']) ? '提现明细' : ($set['texts']['commission_detail'] == '佣金明细' ? '提现明细' : $set['texts']['commission_detail']),
540
+            'commission_pay' => empty($set['texts']['commission_pay']) ? '成功提现佣金' : $set['texts']['commission_pay'],
541
+            'commission_wait' => empty($set['texts']['commission_wait']) ? '待收货佣金' : $set['texts']['commission_wait'],
542
+            'commission_fail' => empty($set['texts']['commission_fail']) ? '无效佣金' : $set['texts']['commission_fail'],
543
+            'commission_charge' => empty($set['texts']['commission_charge']) ? '扣除提现手续费' : $set['texts']['commission_charge'],
544
+            'order' => empty($set['texts']['order']) ? '分销订单' : $set['texts']['order'],
545
+            'c1' => empty($set['texts']['c1']) ? '一级' : $set['texts']['c1'],
546
+            'c2' => empty($set['texts']['c2']) ? '二级' : $set['texts']['c2'],
547
+            'c3' => empty($set['texts']['c3']) ? '三级' : $set['texts']['c3'],
548
+            'mydown' => empty($set['texts']['mydown']) ? '我的下线' : $set['texts']['mydown'],
549
+            'down' => empty($set['texts']['down']) ? '下线' : $set['texts']['down'],
550
+            'up' => empty($set['texts']['up']) ? '推荐人' : $set['texts']['up'],
551
+            'yuan' => empty($set['texts']['yuan']) ? '元' : $set['texts']['yuan'],
552
+            'icode' => empty($set['texts']['icode']) ? '邀请码' : $set['texts']['icode']
553
+        );
554
+        return $set;
555
+    }
556
+}
557
+

+ 178 - 0
addons/ewei_shopv2/core/mobile/goods/wholesalepicker.php Parādīt failu

@@ -0,0 +1,178 @@
1
+<?php
2
+if (!(defined('IN_IA'))) 
3
+{
4
+	exit('Access Denied');
5
+}
6
+class Wholesalepicker_EweiShopV2Page extends MobilePage 
7
+{
8
+	public function main() 
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$id = intval($_GPC['id']);
13
+		$action = trim($_GPC['action']);
14
+		$cremind = false;
15
+		$goods = pdo_fetch('select id,thumb,title,marketprice,total,maxbuy,minbuy,unit,hasoption,showtotal,diyformid,diyformtype,diyfields,isdiscount,presellprice,' . "\n" . '                isdiscount_time,isdiscount_discounts, needfollow, followtip, followurl, `type`,intervalfloor,intervalprice, isverify, maxprice, minprice, merchsale,ispresell,preselltimeend,unite_total,threen' . "\n" . '                from ' . tablename('ewei_shop_goods') . ' where id=:id and uniacid=:uniacid limit 1', array(':id' => $id, ':uniacid' => $_W['uniacid']));
16
+		if (empty($goods)) 
17
+		{
18
+			show_json(0);
19
+		}
20
+		$intervalprice = iunserializer($goods['intervalprice']);
21
+		$goods['minprice'] = 0;
22
+		$goods['maxprice'] = 0;
23
+		if (0 < $goods['intervalfloor']) 
24
+		{
25
+			$goods['intervalprice1'] = $intervalprice[0]['intervalprice'];
26
+			$goods['intervalnum1'] = $intervalprice[0]['intervalnum'];
27
+			$goods['maxprice'] = $intervalprice[0]['intervalprice'];
28
+		}
29
+		if (1 < $goods['intervalfloor']) 
30
+		{
31
+			$goods['intervalprice2'] = $intervalprice[1]['intervalprice'];
32
+			$goods['intervalnum2'] = $intervalprice[1]['intervalnum'];
33
+			$goods['minprice'] = $intervalprice[1]['intervalprice'];
34
+		}
35
+		if (2 < $goods['intervalfloor']) 
36
+		{
37
+			$goods['intervalprice3'] = $intervalprice[2]['intervalprice'];
38
+			$goods['intervalnum3'] = $intervalprice[2]['intervalnum'];
39
+			$goods['minprice'] = $intervalprice[2]['intervalprice'];
40
+		}
41
+		$goods['thistime'] = time();
42
+		$goods = set_medias($goods, 'thumb');
43
+		$openid = $_W['openid'];
44
+		if (is_weixin()) 
45
+		{
46
+			$follow = m('user')->followed($openid);
47
+			if (!(empty($goods['needfollow'])) && !($follow)) 
48
+			{
49
+				$followtip = ((empty($goods['followtip']) ? '如果您想要购买此商品,需要您关注我们的公众号,点击【确定】关注后再来购买吧~' : $goods['followtip']));
50
+				$followurl = ((empty($goods['followurl']) ? $_W['shopset']['share']['followurl'] : $goods['followurl']));
51
+				show_json(2, array('followtip' => $followtip, 'followurl' => $followurl));
52
+			}
53
+		}
54
+		$member = m('member')->getMember($_W['openid']);
55
+		if (empty($openid)) 
56
+		{
57
+			show_json(4);
58
+		}
59
+		if (!(empty($_W['shopset']['wap']['open'])) && !(empty($_W['shopset']['wap']['mustbind'])) && empty($member['mobileverify'])) 
60
+		{
61
+			show_json(3);
62
+		}
63
+		$specs = false;
64
+		$options = false;
65
+		if (!(empty($goods)) && $goods['hasoption']) 
66
+		{
67
+			$specs1 = pdo_fetch('select *  from ' . tablename('ewei_shop_goods_spec') . ' where goodsid=:goodsid and uniacid=:uniacid order by displayorder asc limit 1', array(':goodsid' => $id, ':uniacid' => $_W['uniacid']));
68
+			if (!(empty($specs1))) 
69
+			{
70
+				$hasoption = 1;
71
+				$spec1items = pdo_fetchall('select *  from ' . tablename('ewei_shop_goods_spec_item') . ' where specid=:specid and `show`=1 order by displayorder asc', array(':specid' => $specs1['id']));
72
+				if (!(empty($spec1items))) 
73
+				{
74
+					foreach ($spec1items as &$v ) 
75
+					{
76
+						$v['thumb'] = tomedia($v['thumb']);
77
+					}
78
+					unset($v);
79
+				}
80
+			}
81
+			$specs2 = pdo_fetch('select *  from ' . tablename('ewei_shop_goods_spec') . ' where goodsid=:goodsid and uniacid=:uniacid order by displayorder asc limit 1,1', array(':goodsid' => $id, ':uniacid' => $_W['uniacid']));
82
+			if (!(empty($specs2))) 
83
+			{
84
+				$hasoption = 2;
85
+				$spec2items = pdo_fetchall('select *  from ' . tablename('ewei_shop_goods_spec_item') . ' where specid=:specid and `show`=1 order by displayorder asc', array(':specid' => $specs2['id']));
86
+				if (!(empty($spec2items))) 
87
+				{
88
+					foreach ($spec2items as &$v ) 
89
+					{
90
+						$v['thumb'] = tomedia($v['thumb']);
91
+					}
92
+					unset($v);
93
+				}
94
+			}
95
+			$optionlist = pdo_fetchall('select *  from ' . tablename('ewei_shop_goods_option') . ' where goodsid=:goodsid and uniacid=:uniacid order by displayorder asc', array(':goodsid' => $id, ':uniacid' => $_W['uniacid']));
96
+			$options = array();
97
+			foreach ($optionlist as $option ) 
98
+			{
99
+				$key = $option['specs'];
100
+				if (strstr($key, '_')) 
101
+				{
102
+					$keys = explode('_', $key);
103
+					sort($keys);
104
+					$key = implode('_', $keys);
105
+				}
106
+				$options[$key] = $option;
107
+			}
108
+		}
109
+		else 
110
+		{
111
+			$hasoption = 0;
112
+		}
113
+		if (!(empty($options)) && !(empty($goods['unite_total']))) 
114
+		{
115
+			foreach ($options as &$option ) 
116
+			{
117
+				$option['stock'] = $goods['total'];
118
+			}
119
+		}
120
+		$diyformhtml = '';
121
+		$diyform_plugin = p('diyform');
122
+		if ($diyform_plugin) 
123
+		{
124
+			$fields = false;
125
+			if ($goods['diyformtype'] == 1) 
126
+			{
127
+				if (!(empty($goods['diyformid']))) 
128
+				{
129
+					$diyformid = $goods['diyformid'];
130
+					$formInfo = $diyform_plugin->getDiyformInfo($diyformid);
131
+					$fields = $formInfo['fields'];
132
+				}
133
+			}
134
+			else if ($goods['diyformtype'] == 2) 
135
+			{
136
+				$diyformid = 0;
137
+				$fields = iunserializer($goods['diyfields']);
138
+				if (empty($fields)) 
139
+				{
140
+					$fields = false;
141
+				}
142
+			}
143
+			if (!(empty($fields))) 
144
+			{
145
+				ob_start();
146
+				$inPicker = true;
147
+				$openid = $_W['openid'];
148
+				$member = m('member')->getMember($openid, true);
149
+				$f_data = $diyform_plugin->getLastData(3, 0, $diyformid, $id, $fields, $member);
150
+				$flag = 0;
151
+				if (!(empty($f_data))) 
152
+				{
153
+					foreach ($f_data as $k => $v ) 
154
+					{
155
+						while (!(empty($v))) 
156
+						{
157
+							$flag = 1;
158
+							break;
159
+						}
160
+					}
161
+				}
162
+				if (empty($flag)) 
163
+				{
164
+					$f_data = $diyform_plugin->getLastCartData($id);
165
+				}
166
+				$area_set = m('util')->get_area_config_set();
167
+				$new_area = intval($area_set['new_area']);
168
+				$address_street = intval($area_set['address_street']);
169
+				include $this->template('diyform/formfields');
170
+				$diyformhtml = ob_get_contents();
171
+				ob_clean();
172
+			}
173
+		}
174
+		$goods['canAddCart'] = true;
175
+		show_json(1, array('goods' => $goods, 'spec1items' => $spec1items, 'spec2items' => $spec2items, 'options' => $options, 'diyformhtml' => $diyformhtml, 'hasoption' => $hasoption));
176
+	}
177
+}
178
+?>

+ 148 - 0
addons/ewei_shopv2/core/mobile/index.php Parādīt failu

@@ -0,0 +1,148 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Index_EweiShopV2Page extends MobilePage
7
+{
8
+	public function main()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$_SESSION['newstoreid'] = 0;
13
+		$this->diypage('home');
14
+		$trade = m('common')->getSysset('trade');
15
+
16
+		if (empty($trade['shop_strengthen'])) {
17
+			$order = pdo_fetch('select id,price  from ' . tablename('ewei_shop_order') . ' where uniacid=:uniacid and status = 0 and paytype<>3 and openid=:openid order by createtime desc limit 1', array(':uniacid' => $_W['uniacid'], ':openid' => $_W['openid']));
18
+
19
+			if (!empty($order)) {
20
+				$goods = pdo_fetchall('select g.*,og.total as totals  from ' . tablename('ewei_shop_order_goods') . ' og inner join ' . tablename('ewei_shop_goods') . ' g on og.goodsid = g.id   where og.uniacid=:uniacid    and og.orderid=:orderid  limit 3', array(':uniacid' => $_W['uniacid'], ':orderid' => $order['id']));
21
+				$goodstotal = pdo_fetchcolumn('select COUNT(*)  from ' . tablename('ewei_shop_order_goods') . ' og inner join ' . tablename('ewei_shop_goods') . ' g on og.goodsid = g.id   where og.uniacid=:uniacid    and og.orderid=:orderid ', array(':uniacid' => $_W['uniacid'], ':orderid' => $order['id']));
22
+			}
23
+		}
24
+
25
+		$mid = intval($_GPC['mid']);
26
+		$index_cache = $this->getpage();
27
+
28
+		if (!empty($mid)) {
29
+			$index_cache = preg_replace_callback('/href=[\\\'"]?([^\\\'" ]+).*?[\\\'"]/', function($matches) use($mid) {
30
+				$preg = $matches[1];
31
+
32
+				if (strexists($preg, 'mid=')) {
33
+					return 'href=\'' . $preg . '\'';
34
+				}
35
+
36
+				if (!strexists($preg, 'javascript')) {
37
+					$preg = preg_replace('/(&|\\?)mid=[\\d+]/', '', $preg);
38
+
39
+					if (strexists($preg, '?')) {
40
+						$newpreg = $preg . ('&mid=' . $mid);
41
+					}
42
+					else {
43
+						$newpreg = $preg . ('?mid=' . $mid);
44
+					}
45
+
46
+					return 'href=\'' . $newpreg . '\'';
47
+				}
48
+			}, $index_cache);
49
+		}
50
+
51
+		$shop_data = m('common')->getSysset('shop');
52
+
53
+		if (com('coupon')) {
54
+			$cpinfos = com('coupon')->getInfo();
55
+		}
56
+
57
+		include $this->template();
58
+	}
59
+
60
+	public function get_recommand()
61
+	{
62
+		global $_W;
63
+		global $_GPC;
64
+		$args = array('page' => $_GPC['page'], 'pagesize' => 6, 'isrecommand' => 1, 'order' => 'displayorder desc,createtime desc', 'by' => '');
65
+		$recommand = m('goods')->getList($args);
66
+		show_json(1, array('list' => $recommand['list'], 'pagesize' => $args['pagesize'], 'total' => $recommand['total'], 'page' => intval($_GPC['page'])));
67
+	}
68
+
69
+	private function getcache()
70
+	{
71
+		global $_W;
72
+		global $_GPC;
73
+		return m('common')->createStaticFile(mobileUrl('getpage', NULL, true));
74
+	}
75
+
76
+	public function getpage()
77
+	{
78
+		global $_W;
79
+		global $_GPC;
80
+		$uniacid = $_W['uniacid'];
81
+		$defaults = array(
82
+			'adv'    => array('text' => '幻灯片', 'visible' => 1),
83
+			'search' => array('text' => '搜索栏', 'visible' => 1),
84
+			'nav'    => array('text' => '导航栏', 'visible' => 1),
85
+			'notice' => array('text' => '公告栏', 'visible' => 1),
86
+			'cube'   => array('text' => '魔方栏', 'visible' => 1),
87
+			'banner' => array('text' => '广告栏', 'visible' => 1),
88
+			'goods'  => array('text' => '推荐栏', 'visible' => 1)
89
+			);
90
+		$sorts = isset($_W['shopset']['shop']['indexsort']) ? $_W['shopset']['shop']['indexsort'] : $defaults;
91
+		$sorts['recommand'] = array('text' => '系统推荐', 'visible' => 1);
92
+		$advs = pdo_fetchall('select id,advname,link,thumb from ' . tablename('ewei_shop_adv') . ' where uniacid=:uniacid and iswxapp=0 and enabled=1 order by displayorder desc', array(':uniacid' => $uniacid));
93
+		$navs = pdo_fetchall('select id,navname,url,icon from ' . tablename('ewei_shop_nav') . ' where uniacid=:uniacid and iswxapp=0 and status=1 order by displayorder desc', array(':uniacid' => $uniacid));
94
+		$cubes = is_array($_W['shopset']['shop']['cubes']) ? $_W['shopset']['shop']['cubes'] : array();
95
+		$banners = pdo_fetchall('select id,bannername,link,thumb from ' . tablename('ewei_shop_banner') . ' where uniacid=:uniacid and iswxapp=0 and enabled=1 order by displayorder desc', array(':uniacid' => $uniacid));
96
+		$bannerswipe = $_W['shopset']['shop']['bannerswipe'];
97
+
98
+		if (!empty($_W['shopset']['shop']['indexrecommands'])) {
99
+			$goodids = implode(',', $_W['shopset']['shop']['indexrecommands']);
100
+
101
+			if (!empty($goodids)) {
102
+				$indexrecommands = pdo_fetchall('select id, title, thumb, marketprice,ispresell,presellprice, productprice, minprice, total,type from ' . tablename('ewei_shop_goods') . (' where id in( ' . $goodids . ' ) and uniacid=:uniacid and deleted = 0 and status=1 order by instr(\'' . $goodids . '\',id),displayorder desc'), array(':uniacid' => $uniacid));
103
+
104
+				foreach ($indexrecommands as $key => $value) {
105
+					if (0 < $value['ispresell']) {
106
+						$indexrecommands[$key]['minprice'] = $value['presellprice'];
107
+					}
108
+				}
109
+			}
110
+		}
111
+
112
+		$goodsstyle = $_W['shopset']['shop']['goodsstyle'];
113
+		$notices = pdo_fetchall('select id, title, link, thumb from ' . tablename('ewei_shop_notice') . ' where uniacid=:uniacid and iswxapp=0 and status=1 order by displayorder desc limit 5', array(':uniacid' => $uniacid));
114
+		$seckillinfo = plugin_run('seckill::getTaskSeckillInfo');
115
+		ob_start();
116
+		ob_implicit_flush(false);
117
+		require $this->template('index_tpl');
118
+		return ob_get_clean();
119
+	}
120
+
121
+	public function seckillinfo()
122
+	{
123
+		$seckillinfo = plugin_run('seckill::getTaskSeckillInfo');
124
+		include $this->template('shop/index/seckill_tpl');
125
+		exit();
126
+	}
127
+
128
+	public function qr()
129
+	{
130
+		global $_W;
131
+		global $_GPC;
132
+		$url = trim($_GPC['url']);
133
+		require IA_ROOT . '/framework/library/qrcode/phpqrcode.php';
134
+		QRcode::png($url, false, QR_ECLEVEL_L, 16, 1);
135
+	}
136
+
137
+	public function share_url()
138
+	{
139
+		global $_W;
140
+		global $_GPC;
141
+		$url = trim($_GPC['url']);
142
+		$account_api = WeAccount::create($_W['acid']);
143
+		$jssdkconfig = $account_api->getJssdkConfig($url);
144
+		show_json(1, $jssdkconfig);
145
+	}
146
+}
147
+
148
+?>

+ 242 - 0
addons/ewei_shopv2/core/mobile/member/activation.php Parādīt failu

@@ -0,0 +1,242 @@
1
+<?php  if( !defined("IN_IA") ) 
2
+{
3
+	exit( "Access Denied" );
4
+}
5
+class Activation_EweiShopV2Page extends MobileLoginPage 
6
+{
7
+	public function main() 
8
+	{
9
+		global $_W;
10
+		global $_GPC;
11
+		$iserror = false;
12
+		$card_id = $_GPC["card_id"];
13
+		$encrypt_code = $_GPC["encrypt_code"];
14
+		if( empty($card_id) || empty($encrypt_code) ) 
15
+		{
16
+			$iserror = true;
17
+		}
18
+		$encrypt_code = htmlspecialchars_decode($encrypt_code, ENT_QUOTES);
19
+		$result = com_run("wxcard::wxCardCodeDecrypt", $encrypt_code);
20
+		if( empty($result) || is_wxerror($result) ) 
21
+		{
22
+			$iserror = true;
23
+		}
24
+		$code = $result["code"];
25
+		if( empty($_W["openid"]) ) 
26
+		{
27
+			$iserror = true;
28
+		}
29
+		$item = pdo_fetch("select * from " . tablename("ewei_shop_member") . " where uniacid=:uniacid and openid =:openid limit 1 ", array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] ));
30
+		if( $iserror ) 
31
+		{
32
+			$this->message(array( "message" => "激活链接错误!", "title" => "激活链接错误!", "buttondisplay" => true ), mobileUrl("member"), "error");
33
+		}
34
+		$arr = array( "membercardid" => $card_id, "membercardcode" => $code, "membershipnumber" => $code, "membercardactive" => 0 );
35
+		$CardActivation = m("common")->getSysset("memberCardActivation");
36
+		pdo_update("ewei_shop_member", $arr, array( "openid" => $_W["openid"], "uniacid" => $_W["uniacid"] ));
37
+		if( empty($CardActivation["openactive"]) ) 
38
+		{
39
+			$result = com_run("wxcard::ActivateMembercardbyopenid", $_W["openid"]);
40
+			if( empty($result) || is_wxerror($result) ) 
41
+			{
42
+				$this->message(array( "message" => "会员卡激活失败!", "title" => "激活链接错误!", "buttondisplay" => true ), mobileUrl("member"), "error");
43
+			}
44
+			else 
45
+			{
46
+				if( empty($item["membercardactive"]) ) 
47
+				{
48
+					pdo_update("ewei_shop_member", array( "membercardactive" => 1 ), array( "openid" => $_W["openid"], "uniacid" => $_W["uniacid"] ));
49
+					$this->sendGift($_W["openid"]);
50
+					$this->message(array( "message" => "您的会员卡已成功激活!", "title" => "激活成功!", "buttondisplay" => true ), mobileUrl("member"), "success");
51
+				}
52
+				else 
53
+				{
54
+					header("location: " . mobileUrl("member"));
55
+				}
56
+			}
57
+		}
58
+		if( empty($CardActivation) ) 
59
+		{
60
+			$needrealname = 0;
61
+			$needmobile = 0;
62
+			$needsmscode = 0;
63
+			$needsbirthday = 0;
64
+			$needsidnumber = 0;
65
+		}
66
+		else 
67
+		{
68
+			$needrealname = intval($CardActivation["realname"]);
69
+			$needmobile = intval($CardActivation["mobile"]);
70
+			$needsmscode = intval($CardActivation["sms_active"]);
71
+			$needsbirthday = intval($CardActivation["birthday"]);
72
+			$needsidnumber = intval($CardActivation["idnumber"]);
73
+		}
74
+		include($this->template());
75
+	}
76
+	public function submit() 
77
+	{
78
+		global $_W;
79
+		global $_GPC;
80
+		$iserror = false;
81
+		$card_id = $_GPC["card_id"];
82
+		$encrypt_code = $_GPC["encrypt_code"];
83
+		if( empty($card_id) || empty($encrypt_code) ) 
84
+		{
85
+			show_json(0, "激活链接错误!");
86
+		}
87
+		$encrypt_code = htmlspecialchars_decode($encrypt_code, ENT_QUOTES);
88
+		$result = com_run("wxcard::wxCardCodeDecrypt", $encrypt_code);
89
+		if( empty($result) || is_wxerror($result) ) 
90
+		{
91
+			show_json(0, "激活链接错误!");
92
+		}
93
+		$code = $result["code"];
94
+		if( empty($_W["openid"]) ) 
95
+		{
96
+			show_json(0, "激活链接错误!");
97
+		}
98
+		$item = pdo_fetch("select * from " . tablename("ewei_shop_member") . " where uniacid=:uniacid and openid =:openid limit 1 ", array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] ));
99
+		$arr = array( "membercardid" => $card_id, "membercardcode" => $code, "membershipnumber" => $code, "membercardactive" => 0 );
100
+		$CardActivation = m("common")->getSysset("memberCardActivation");
101
+		if( !empty($CardActivation["openactive"]) ) 
102
+		{
103
+			if( !empty($CardActivation["sms_active"]) && !empty($CardActivation["mobile"]) ) 
104
+			{
105
+				@session_start();
106
+				$key = "__ewei_shopv2_member_verifycodesession_" . $_W["uniacid"] . "_" . trim($_GPC["mobile"]);
107
+				$code = $_SESSION[$key];
108
+				if( empty($code) ) 
109
+				{
110
+					show_json(0, "请获取验证码!");
111
+				}
112
+				if( trim($_GPC["sms_code"]) != $code ) 
113
+				{
114
+					show_json(0, "验证码错误!");
115
+				}
116
+			}
117
+			if( !empty($CardActivation["realname"]) ) 
118
+			{
119
+				if( empty($_GPC["realname"]) ) 
120
+				{
121
+					show_json(0, "真实姓名不能为空!");
122
+				}
123
+				$arr["realname"] = trim($_GPC["realname"]);
124
+			}
125
+			if( !empty($CardActivation["mobile"]) ) 
126
+			{
127
+				if( empty($_GPC["mobile"]) ) 
128
+				{
129
+					show_json(0, "电话号码不能为空");
130
+				}
131
+				$arr["mobile"] = trim($_GPC["mobile"]);
132
+			}
133
+			if( !empty($CardActivation["birthday"]) ) 
134
+			{
135
+				if( empty($_GPC["birthyear"]) ) 
136
+				{
137
+					show_json(0, "出生日期未选择");
138
+				}
139
+				$arr["birthyear"] = trim($_GPC["birthyear"]);
140
+				$arr["birthmonth"] = trim($_GPC["birthmonth"]);
141
+				$arr["birthday"] = trim($_GPC["birthday"]);
142
+			}
143
+			if( !empty($CardActivation["idnumber"]) ) 
144
+			{
145
+				if( empty($_GPC["idnumber"]) ) 
146
+				{
147
+					show_json(0, "身份证号码未填写");
148
+				}
149
+				$arr["idnumber"] = trim($_GPC["idnumber"]);
150
+			}
151
+		}
152
+		pdo_update("ewei_shop_member", $arr, array( "openid" => $_W["openid"], "uniacid" => $_W["uniacid"] ));
153
+		$result = com_run("wxcard::ActivateMembercardbyopenid", $_W["openid"]);
154
+		if( empty($result) || is_wxerror($result) ) 
155
+		{
156
+			show_json(0, "会员卡激活失败");
157
+		}
158
+		else 
159
+		{
160
+			if( empty($item["membercardactive"]) ) 
161
+			{
162
+				$this->sendGift($_W["openid"]);
163
+			}
164
+			pdo_update("ewei_shop_member", array( "membercardactive" => 1 ), array( "openid" => $_W["openid"], "uniacid" => $_W["uniacid"] ));
165
+			show_json(1, "您的会员卡已成功激活");
166
+		}
167
+	}
168
+	public function sendGift($openid) 
169
+	{
170
+		$CardActivation = m("common")->getSysset("memberCardActivation");
171
+		$credit1 = intval($CardActivation["credit1"]);
172
+		$credit2 = intval($CardActivation["credit2"]);
173
+		$couponid = intval($CardActivation["couponid"]);
174
+		$levelid = intval($CardActivation["levelid"]);
175
+		if( !empty($credit1) ) 
176
+		{
177
+			m("member")->setCredit($openid, "credit1", $credit1, array( 0, "激活会员卡,积分+" . $credit1 ));
178
+		}
179
+		if( !empty($credit2) ) 
180
+		{
181
+			m("member")->setCredit($openid, "credit2", $credit2, array( 0, "激活会员卡,余额+" . $credit2 ));
182
+		}
183
+		if( !empty($couponid) ) 
184
+		{
185
+			$member = m("member")->getMember($openid);
186
+			if( com("coupon") ) 
187
+			{
188
+				com("coupon")->poster($member, $couponid, 1, 10);
189
+			}
190
+		}
191
+		if( !empty($levelid) ) 
192
+		{
193
+			$member = m("member")->upgradeLevelByLevelId($openid, $levelid);
194
+		}
195
+	}
196
+	public function verifycode() 
197
+	{
198
+		global $_W;
199
+		global $_GPC;
200
+		@session_start();
201
+		$mobile = trim($_GPC["mobile"]);
202
+		if( empty($mobile) ) 
203
+		{
204
+			show_json(0, "请输入手机号");
205
+		}
206
+		if( !empty($_SESSION["verifycodesendtime"]) && time() < $_SESSION["verifycodesendtime"] + 60 ) 
207
+		{
208
+			show_json(0, "请求频繁请稍后重试");
209
+		}
210
+		$member = pdo_fetch("select id,openid,mobile,pwd,salt from " . tablename("ewei_shop_member") . " where mobile=:mobile and openid <>:openid  and mobileverify=1 and uniacid=:uniacid limit 1", array( ":mobile" => $mobile, ":openid" => $_W["openid"], ":uniacid" => $_W["uniacid"] ));
211
+		if( !empty($member) ) 
212
+		{
213
+			show_json(0, "该手机号已经被绑定");
214
+		}
215
+		$CardActivation = m("common")->getSysset("memberCardActivation");
216
+		$sms_id = $CardActivation["sms_id"];
217
+		if( empty($sms_id) ) 
218
+		{
219
+			show_json(0, "短信发送失败(NOSMSID)");
220
+		}
221
+		$key = "__ewei_shopv2_member_verifycodesession_" . $_W["uniacid"] . "_" . $mobile;
222
+		$code = random(5, true);
223
+		$shopname = $_W["shopset"]["shop"]["name"];
224
+		$ret = array( "status" => 0, "message" => "发送失败" );
225
+		if( com("sms") ) 
226
+		{
227
+			$ret = com("sms")->send($mobile, $sms_id, array( "验证码" => $code, "商城名称" => (!empty($shopname) ? $shopname : "商城名称") ));
228
+		}
229
+		if( $ret["status"] ) 
230
+		{
231
+			$_SESSION[$key] = $code;
232
+			$_SESSION["verifycodesendtime"] = time();
233
+			show_json(1, "短信发送成功");
234
+		}
235
+		show_json(0, $ret["message"]);
236
+	}
237
+	public function success() 
238
+	{
239
+		$this->message(array( "message" => "您的会员卡已成功激活!", "title" => "激活成功!", "buttondisplay" => true ), mobileUrl("member"), "success");
240
+	}
241
+}
242
+?>

+ 230 - 0
addons/ewei_shopv2/core/mobile/member/address.php Parādīt failu

@@ -0,0 +1,230 @@
1
+<?php  if( !defined("IN_IA") ) 
2
+{
3
+	exit( "Access Denied" );
4
+}
5
+class Address_EweiShopV2Page extends MobileLoginPage 
6
+{
7
+	public function main() 
8
+	{
9
+		global $_W;
10
+		global $_GPC;
11
+		global $_S;
12
+		$area_set = m("util")->get_area_config_set();
13
+		$new_area = intval($area_set["new_area"]);
14
+		$address_street = intval($area_set["address_street"]);
15
+		$pindex = intval($_GPC["page"]);
16
+		$psize = 20;
17
+		$condition = " and openid=:openid and deleted=0 and  `uniacid` = :uniacid  ";
18
+		$params = array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] );
19
+		$sql = "SELECT COUNT(*) FROM " . tablename("ewei_shop_member_address") . " where 1 " . $condition;
20
+		$total = pdo_fetchcolumn($sql, $params);
21
+		$sql = "SELECT * FROM " . tablename("ewei_shop_member_address") . " where 1 " . $condition . " ORDER BY `id` DESC";
22
+		if( $pindex != 0 ) 
23
+		{
24
+			$sql .= "LIMIT " . ($pindex - 1) * $psize . "," . $psize;
25
+		}
26
+		$list = pdo_fetchall($sql, $params);
27
+		include($this->template());
28
+	}
29
+	public function post() 
30
+	{
31
+		global $_W;
32
+		global $_GPC;
33
+		$id = intval($_GPC["id"]);
34
+		$area_set = m("util")->get_area_config_set();
35
+		$new_area = intval($area_set["new_area"]);
36
+		$address_street = intval($area_set["address_street"]);
37
+		if( !empty($id) ) 
38
+		{
39
+			$address = pdo_fetch("select * from " . tablename("ewei_shop_member_address") . " where id=:id and openid=:openid and uniacid=:uniacid limit 1 ", array( ":id" => $id, ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] ));
40
+			if( empty($address["datavalue"]) ) 
41
+			{
42
+				$provinceName = $address["province"];
43
+				$citysName = $address["city"];
44
+				$countyName = $address["area"];
45
+				$province_code = 0;
46
+				$citys_code = 0;
47
+				$county_code = 0;
48
+				$path = EWEI_SHOPV2_PATH . "static/js/dist/area/AreaNew.xml";
49
+				$xml = file_get_contents($path);
50
+				$array = xml2array($xml);
51
+				$newArr = array( );
52
+				if( is_array($array["province"]) ) 
53
+				{
54
+					foreach( $array["province"] as $i => $v ) 
55
+					{
56
+						if( 0 < $i && $v["@attributes"]["name"] == $provinceName && !is_null($provinceName) && $provinceName != "" ) 
57
+						{
58
+							$province_code = $v["@attributes"]["code"];
59
+							if( is_array($v["city"]) ) 
60
+							{
61
+								if( !isset($v["city"][0]) ) 
62
+								{
63
+									$v["city"] = array( $v["city"] );
64
+								}
65
+								foreach( $v["city"] as $ii => $vv ) 
66
+								{
67
+									if( $vv["@attributes"]["name"] == $citysName && !is_null($citysName) && $citysName != "" ) 
68
+									{
69
+										$citys_code = $vv["@attributes"]["code"];
70
+										if( is_array($vv["county"]) ) 
71
+										{
72
+											if( !isset($vv["county"][0]) ) 
73
+											{
74
+												$vv["county"] = array( $vv["county"] );
75
+											}
76
+											foreach( $vv["county"] as $iii => $vvv ) 
77
+											{
78
+												if( $vvv["@attributes"]["name"] == $countyName && !is_null($countyName) && $countyName != "" ) 
79
+												{
80
+													$county_code = $vvv["@attributes"]["code"];
81
+												}
82
+											}
83
+										}
84
+									}
85
+								}
86
+							}
87
+						}
88
+					}
89
+				}
90
+				if( $province_code != 0 && $citys_code != 0 && $county_code != 0 ) 
91
+				{
92
+					$address["datavalue"] = $province_code . " " . $citys_code . " " . $county_code;
93
+					pdo_update("ewei_shop_member_address", $address, array( "id" => $id, "uniacid" => $_W["uniacid"], "openid" => $_W["openid"] ));
94
+				}
95
+			}
96
+			$show_data = 1;
97
+			if( !empty($new_area) && empty($address["datavalue"]) || empty($new_area) && !empty($address["datavalue"]) ) 
98
+			{
99
+				$show_data = 0;
100
+			}
101
+		}
102
+		include($this->template());
103
+	}
104
+	public function setdefault() 
105
+	{
106
+		global $_W;
107
+		global $_GPC;
108
+		$id = intval($_GPC["id"]);
109
+		$data = pdo_fetch("select id from " . tablename("ewei_shop_member_address") . " where id=:id and deleted=0 and uniacid=:uniacid limit 1", array( ":uniacid" => $_W["uniacid"], ":id" => $id ));
110
+		if( empty($data) ) 
111
+		{
112
+			show_json(0, "地址未找到");
113
+		}
114
+		pdo_update("ewei_shop_member_address", array( "isdefault" => 0 ), array( "uniacid" => $_W["uniacid"], "openid" => $_W["openid"] ));
115
+		pdo_update("ewei_shop_member_address", array( "isdefault" => 1 ), array( "id" => $id, "uniacid" => $_W["uniacid"], "openid" => $_W["openid"] ));
116
+		show_json(1);
117
+	}
118
+	private function extractNumber($string) 
119
+	{
120
+		$string = preg_replace("# #", "", $string);
121
+		preg_match("/\\d{11}/", $string, $result);
122
+		return (string) $result[0];
123
+	}
124
+	public function submit() 
125
+	{
126
+		global $_W;
127
+		global $_GPC;
128
+		$id = intval($_GPC["id"]);
129
+		$data = $_GPC["addressdata"];
130
+		$data["mobile"] = $this->extractNumber($data["mobile"]);
131
+		$areas = explode(" ", $data["areas"]);
132
+		list($data["province"], $data["city"], $data["area"]) = $areas;
133
+		$data["street"] = trim($data["street"]);
134
+		$data["datavalue"] = trim($data["datavalue"]);
135
+		$data["streetdatavalue"] = trim($data["streetdatavalue"]);
136
+		$isdefault = intval($data["isdefault"]);
137
+		unset($data["isdefault"]);
138
+		unset($data["areas"]);
139
+		$data["openid"] = $_W["openid"];
140
+		$data["uniacid"] = $_W["uniacid"];
141
+		if( empty($id) ) 
142
+		{
143
+			$addresscount = pdo_fetchcolumn("SELECT count(*) FROM " . tablename("ewei_shop_member_address") . " where openid=:openid and deleted=0 and `uniacid` = :uniacid ", array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] ));
144
+			if( $addresscount <= 0 ) 
145
+			{
146
+				$data["isdefault"] = 1;
147
+			}
148
+			pdo_insert("ewei_shop_member_address", $data);
149
+			$id = pdo_insertid();
150
+		}
151
+		else 
152
+		{
153
+			$data["lng"] = "";
154
+			$data["lat"] = "";
155
+			pdo_update("ewei_shop_member_address", $data, array( "id" => $id, "uniacid" => $_W["uniacid"], "openid" => $_W["openid"] ));
156
+		}
157
+		if( !empty($isdefault) ) 
158
+		{
159
+			pdo_update("ewei_shop_member_address", array( "isdefault" => 0 ), array( "uniacid" => $_W["uniacid"], "openid" => $_W["openid"] ));
160
+			pdo_update("ewei_shop_member_address", array( "isdefault" => 1 ), array( "id" => $id, "uniacid" => $_W["uniacid"], "openid" => $_W["openid"] ));
161
+		}
162
+		show_json(1, array( "addressid" => $id ));
163
+	}
164
+	public function delete() 
165
+	{
166
+		global $_W;
167
+		global $_GPC;
168
+		$id = intval($_GPC["id"]);
169
+		$data = pdo_fetch("select id,isdefault from " . tablename("ewei_shop_member_address") . " where  id=:id and openid=:openid and deleted=0 and uniacid=:uniacid  limit 1", array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"], ":id" => $id ));
170
+		if( empty($data) ) 
171
+		{
172
+			show_json(0, "地址未找到");
173
+		}
174
+		pdo_update("ewei_shop_member_address", array( "deleted" => 1 ), array( "id" => $id ));
175
+		if( $data["isdefault"] == 1 ) 
176
+		{
177
+			pdo_update("ewei_shop_member_address", array( "isdefault" => 0 ), array( "uniacid" => $_W["uniacid"], "openid" => $_W["openid"], "id" => $id ));
178
+			$data2 = pdo_fetch("select id from " . tablename("ewei_shop_member_address") . " where openid=:openid and deleted=0 and uniacid=:uniacid order by id desc limit 1", array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] ));
179
+			if( !empty($data2) ) 
180
+			{
181
+				pdo_update("ewei_shop_member_address", array( "isdefault" => 1 ), array( "uniacid" => $_W["uniacid"], "openid" => $_W["openid"], "id" => $data2["id"] ));
182
+				show_json(1, array( "defaultid" => $data2["id"] ));
183
+			}
184
+		}
185
+		show_json(1);
186
+	}
187
+	public function selector() 
188
+	{
189
+		global $_W;
190
+		global $_GPC;
191
+		$area_set = m("util")->get_area_config_set();
192
+		$new_area = intval($area_set["new_area"]);
193
+		$address_street = intval($area_set["address_street"]);
194
+		$condition = " and openid=:openid and deleted=0 and  `uniacid` = :uniacid  ";
195
+		$params = array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] );
196
+		$sql = "SELECT * FROM " . tablename("ewei_shop_member_address") . " where 1 " . $condition . " ORDER BY isdefault desc, id DESC ";
197
+		$list = pdo_fetchall($sql, $params);
198
+		include($this->template());
199
+		exit();
200
+	}
201
+	public function getselector() 
202
+	{
203
+		global $_W;
204
+		global $_GPC;
205
+		$condition = " and openid=:openid and deleted=0 and  `uniacid` = :uniacid  ";
206
+		$params = array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] );
207
+		$keywords = $_GPC["keywords"];
208
+		if( !empty($keywords) ) 
209
+		{
210
+			$condition .= " AND (`realname` LIKE :keywords OR `mobile` LIKE :keywords OR `province` LIKE :keywords OR `city` LIKE :keywords OR `area` LIKE :keywords OR `address` LIKE :keywords OR `street` LIKE :keywords)";
211
+			$params[":keywords"] = "%" . trim($keywords) . "%";
212
+		}
213
+		$sql = "SELECT *  FROM " . tablename("ewei_shop_member_address") . " where 1 " . $condition . " ORDER BY isdefault desc, id DESC ";
214
+		$list = pdo_fetchall($sql, $params);
215
+		foreach( $list as &$item ) 
216
+		{
217
+			$item["editurl"] = mobileUrl("member/address/post", array( "id" => $item["id"] ));
218
+		}
219
+		unset($item);
220
+		if( 0 < count($list) ) 
221
+		{
222
+			show_json(1, array( "list" => $list ));
223
+		}
224
+		else 
225
+		{
226
+			show_json(0);
227
+		}
228
+	}
229
+}
230
+?>

+ 194 - 0
addons/ewei_shopv2/core/mobile/member/bind.php Parādīt failu

@@ -0,0 +1,194 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Bind_EweiShopV2Page extends MobileLoginPage
7
+{
8
+	protected $member;
9
+
10
+	public function __construct()
11
+	{
12
+		global $_W;
13
+		global $_GPC;
14
+		parent::__construct();
15
+	}
16
+
17
+	public function main()
18
+	{
19
+		global $_W;
20
+		global $_GPC;
21
+		@session_start();
22
+		$member = m('member')->getMember($_W['openid']);
23
+		$wapset = m('common')->getSysset('wap');
24
+		$appset = m('common')->getSysset('app');
25
+
26
+		if (!p('threen')) {
27
+			if (empty($wapset['open']) && !empty($appset['isclose'])) {
28
+				$this->message('未开启绑定设置');
29
+			}
30
+		}
31
+
32
+		$bind = !empty($member['mobile']) && !empty($member['mobileverify']) ? 1 : 0;
33
+
34
+		if ($_W['ispost']) {
35
+			$mobile = trim($_GPC['mobile']);
36
+			$verifycode = trim($_GPC['verifycode']);
37
+			$pwd = trim($_GPC['pwd']);
38
+			$confirm = intval($_GPC['confirm']);
39
+			$key = '__ewei_shopv2_member_verifycodesession_' . $_W['uniacid'] . '_' . $mobile;
40
+			if (!isset($_SESSION[$key]) || $_SESSION[$key] !== $verifycode || !isset($_SESSION['verifycodesendtime']) || $_SESSION['verifycodesendtime'] + 600 < time()) {
41
+				show_json(0, '验证码错误或已过期');
42
+			}
43
+
44
+			$member2 = pdo_fetch('select * from ' . tablename('ewei_shop_member') . ' where mobile=:mobile and uniacid=:uniacid and mobileverify=1 limit 1', array(':mobile' => $mobile, ':uniacid' => $_W['uniacid']));
45
+
46
+			if (empty($member2)) {
47
+				$salt = m('account')->getSalt();
48
+				$data = array('mobile' => $mobile, 'pwd' => md5($pwd . $salt), 'salt' => $salt, 'mobileverify' => 1);
49
+
50
+				if (!empty($_GPC['realname'])) {
51
+					$data['realname'] = trim($_GPC['realname']);
52
+				}
53
+
54
+				if (!empty($_GPC['birthyear'])) {
55
+					$data['birthyear'] = trim($_GPC['birthyear']);
56
+					$data['birthmonth'] = trim($_GPC['birthmonth']);
57
+					$data['birthday'] = trim($_GPC['birthday']);
58
+				}
59
+
60
+				if (!empty($_GPC['idnumber'])) {
61
+					$data['idnumber'] = trim($_GPC['idnumber']);
62
+				}
63
+
64
+				if (!empty($_GPC['bindwechat'])) {
65
+					$data['weixin'] = trim($_GPC['bindwechat']);
66
+				}
67
+
68
+				m('bind')->update($member['id'], $data);
69
+				unset($_SESSION[$key]);
70
+				m('account')->setLogin($member['id']);
71
+
72
+				if (empty($member['mobileverify'])) {
73
+					m('bind')->sendCredit($member);
74
+				}
75
+
76
+				if (p('task')) {
77
+					p('task')->checkTaskReward('member_info', 1, $_W['openid']);
78
+				}
79
+
80
+				if (p('task')) {
81
+					p('task')->checkTaskProgress(1, 'info_phone');
82
+				}
83
+
84
+				show_json(1, 'bind success (0)');
85
+			}
86
+
87
+			if ($member['id'] == $member2['id']) {
88
+				show_json(0, '此手机号已与当前账号绑定');
89
+			}
90
+
91
+			if (m('bind')->iswxm($member) && m('bind')->iswxm($member2)) {
92
+				if ($confirm) {
93
+					$salt = m('account')->getSalt();
94
+					m('bind')->update($member['id'], array('mobile' => $mobile, 'pwd' => md5($pwd . $salt), 'salt' => $salt, 'mobileverify' => 1));
95
+					m('bind')->update($member2['id'], array('mobileverify' => 0));
96
+					unset($_SESSION[$key]);
97
+					m('account')->setLogin($member['id']);
98
+
99
+					if (p('task')) {
100
+						p('task')->checkTaskReward('member_info', 1, $_W['openid']);
101
+					}
102
+
103
+					if (p('task')) {
104
+						p('task')->checkTaskProgress(1, 'info_phone');
105
+					}
106
+
107
+					show_json(1, 'bind success (1)');
108
+				}
109
+				else {
110
+					show_json(-1, '<center>此手机号已与其他帐号绑定<br>如果继续将会解绑之前帐号<br>确定继续吗?</center>');
111
+				}
112
+			}
113
+
114
+			if (!m('bind')->iswxm($member2)) {
115
+				if ($confirm) {
116
+					$result = m('bind')->merge($member2, $member);
117
+
118
+					if (empty($result['errno'])) {
119
+						show_json(0, $result['message']);
120
+					}
121
+
122
+					$salt = m('account')->getSalt();
123
+					m('bind')->update($member['id'], array('mobile' => $mobile, 'pwd' => md5($pwd . $salt), 'salt' => $salt, 'mobileverify' => 1));
124
+					unset($_SESSION[$key]);
125
+					m('account')->setLogin($member['id']);
126
+
127
+					if (p('task')) {
128
+						p('task')->checkTaskReward('member_info', 1, $_W['openid']);
129
+					}
130
+
131
+					if (p('task')) {
132
+						p('task')->checkTaskProgress(1, 'info_phone');
133
+					}
134
+
135
+					show_json(1, 'bind success (2)');
136
+				}
137
+				else {
138
+					show_json(-1, '<center>此手机号已通过其他方式注册<br>如果继续将会合并账号信息<br>确定继续吗?</center>');
139
+				}
140
+			}
141
+
142
+			if (!m('bind')->iswxm($member)) {
143
+				if ($confirm) {
144
+					$result = m('bind')->merge($member, $member2);
145
+
146
+					if (empty($result['errno'])) {
147
+						show_json(0, $result['message']);
148
+					}
149
+
150
+					$salt = m('account')->getSalt();
151
+					m('bind')->update($member2['id'], array('mobile' => $mobile, 'pwd' => md5($pwd . $salt), 'salt' => $salt, 'mobileverify' => 1));
152
+					unset($_SESSION[$key]);
153
+					m('account')->setLogin($member2['id']);
154
+
155
+					if (p('task')) {
156
+						p('task')->checkTaskReward('member_info', 1, $_W['openid']);
157
+					}
158
+
159
+					if (p('task')) {
160
+						p('task')->checkTaskProgress(1, 'info_phone');
161
+					}
162
+
163
+					show_json(1, 'bind success (3)');
164
+				}
165
+				else {
166
+					show_json(-1, '<center>此手机号已通过其他方式注册<br>如果继续将会合并账号信息<br>确定继续吗?</center>');
167
+				}
168
+			}
169
+		}
170
+
171
+		$sendtime = $_SESSION['verifycodesendtime'];
172
+		if (empty($sendtime) || $sendtime + 60 < time()) {
173
+			$endtime = 0;
174
+		}
175
+		else {
176
+			$endtime = 60 - (time() - $sendtime);
177
+		}
178
+
179
+		include $this->template();
180
+	}
181
+
182
+	public function getbindinfo()
183
+	{
184
+		$wap = m('common')->getSysset('wap');
185
+		$nohasbindinfo = 0;
186
+		if (empty($wap['bindrealname']) && empty($wap['bindbirthday']) && empty($wap['bindidnumber']) && empty($wap['bindwechat'])) {
187
+			$nohasbindinfo = 1;
188
+		}
189
+
190
+		show_json(1, array('nohasbindinfo' => $nohasbindinfo, 'bindrealname' => empty($wap['bindrealname']) ? 0 : 1, 'bindbirthday' => empty($wap['bindbirthday']) ? 0 : 1, 'bindidnumber' => empty($wap['bindidnumber']) ? 0 : 1, 'bindwechat' => empty($wap['bindwechat']) ? 0 : 1));
191
+	}
192
+}
193
+
194
+?>

+ 638 - 0
addons/ewei_shopv2/core/mobile/member/cart.php Parādīt failu

@@ -0,0 +1,638 @@
1
+<?php 
2
+//修复无法添加购物车
3
+if( !defined("IN_IA") ) 
4
+{
5
+	exit( "Access Denied" );
6
+}
7
+class Cart_EweiShopV2Page extends MobileLoginPage 
8
+{
9
+	public function main() 
10
+	{
11
+		global $_W;
12
+		global $_GPC;
13
+		$merch_plugin = p("merch");
14
+		$merch_data = m("common")->getPluginset("merch");
15
+		if( $merch_plugin && $merch_data["is_openmerch"] ) 
16
+		{
17
+			include($this->template("merch/member/cart"));
18
+			exit();
19
+		}
20
+		include($this->template());
21
+	}
22
+	public function get_list() 
23
+	{
24
+		global $_W;
25
+		global $_GPC;
26
+		$uniacid = $_W["uniacid"];
27
+		$openid = $_W["openid"];
28
+		if( p("newstore") ) 
29
+		{
30
+			$condition = " and f.uniacid= :uniacid and f.openid=:openid and f.deleted=0 and f.isnewstore=0";
31
+		}
32
+		else 
33
+		{
34
+			$condition = " and f.uniacid= :uniacid and f.openid=:openid and f.deleted=0";
35
+		}
36
+		$params = array( ":uniacid" => $uniacid, ":openid" => $openid );
37
+		$list = array( );
38
+		$total = 0;
39
+		$totalprice = 0;
40
+		$ischeckall = true;
41
+		$level = m("member")->getLevel($openid);
42
+		$sql = "SELECT f.id,f.total,f.goodsid,g.total as stock,g.preselltimeend,g.presellprice as gpprice,g.hasoption, o.stock as optionstock,g.presellprice,g.ispresell, g.maxbuy,g.title,g.thumb,ifnull(o.marketprice, g.marketprice) as marketprice," . " g.productprice,o.title as optiontitle,o.presellprice,f.optionid,o.specs,g.minbuy,g.maxbuy,g.unit,g.merchid,g.checked,g.isdiscount_discounts,g.isdiscount,g.isdiscount_time,g.isnodiscount,g.discounts,g.merchsale" . " ,f.selected,g.type,g.intervalfloor,g.intervalprice  FROM " . tablename("ewei_shop_member_cart") . " f " . " left join " . tablename("ewei_shop_goods") . " g on f.goodsid = g.id " . " left join " . tablename("ewei_shop_goods_option") . " o on f.optionid = o.id " . " where 1 " . $condition . " ORDER BY `id` DESC ";
43
+		$list = pdo_fetchall($sql, $params);
44
+		foreach( $list as &$g ) 
45
+		{
46
+			if( $g["type"] == 4 ) 
47
+			{
48
+				$intervalprice = iunserializer($g["intervalprice"]);
49
+				if( 0 < $g["intervalfloor"] ) 
50
+				{
51
+					$g["intervalprice1"] = $intervalprice[0]["intervalprice"];
52
+					$g["intervalnum1"] = $intervalprice[0]["intervalnum"];
53
+				}
54
+				if( 1 < $g["intervalfloor"] ) 
55
+				{
56
+					$g["intervalprice2"] = $intervalprice[1]["intervalprice"];
57
+					$g["intervalnum2"] = $intervalprice[1]["intervalnum"];
58
+				}
59
+				if( 2 < $g["intervalfloor"] ) 
60
+				{
61
+					$g["intervalprice3"] = $intervalprice[2]["intervalprice"];
62
+					$g["intervalnum3"] = $intervalprice[2]["intervalnum"];
63
+				}
64
+			}
65
+			if( 0 < $g["ispresell"] && ($g["preselltimeend"] == 0 || time() < $g["preselltimeend"]) ) 
66
+			{
67
+				$g["marketprice"] = (0 < intval($g["hasoption"]) ? $g["presellprice"] : $g["gpprice"]);
68
+			}
69
+			$g["thumb"] = tomedia($g["thumb"]);
70
+			$seckillinfo = plugin_run("seckill::getSeckill", $g["goodsid"], $g["optionid"], true, $_W["openid"]);
71
+			if( !empty($g["optionid"]) ) 
72
+			{
73
+				$g["stock"] = $g["optionstock"];
74
+				if( !empty($g["specs"]) ) 
75
+				{
76
+					$thumb = m("goods")->getSpecThumb($g["specs"]);
77
+					if( !empty($thumb) ) 
78
+					{
79
+						$g["thumb"] = tomedia($thumb);
80
+					}
81
+				}
82
+				$optionData = pdo_fetch("SELECT * FROM " . tablename("ewei_shop_goods_option") . " WHERE uniacid = " . intval($_W["uniacid"]) . " AND id = " . intval($g["optionid"]));
83
+				if( empty($optionData) || $optionData == false ) 
84
+				{
85
+					pdo_update("ewei_shop_member_cart", array( "deleted" => 1 ), array( "id" => $g["id"] ));
86
+				}
87
+			}
88
+			if( $g["selected"] ) 
89
+			{
90
+				$prices = m("order")->getGoodsDiscountPrice($g, $level, 1);
91
+				$total += $g["total"];
92
+				$g["ggprice"] = $prices["price"];
93
+				$g["marketprice"] = $g["ggprice"];
94
+				$g["discounttype"] = $prices["discounttype"];
95
+				if( $seckillinfo && $seckillinfo["status"] == 0 ) 
96
+				{
97
+					$seckilllast = 0;
98
+					if( 0 < $seckillinfo["maxbuy"] ) 
99
+					{
100
+						$seckilllast = $seckillinfo["maxbuy"] - $seckillinfo["selfcount"];
101
+					}
102
+					$normal = $g["total"] - $seckilllast;
103
+					if( $normal <= 0 ) 
104
+					{
105
+						$normal = 0;
106
+					}
107
+					$totalprice += $seckillinfo["price"] * $seckilllast + $g["marketprice"] * $normal;
108
+					$g["seckillmaxbuy"] = $seckillinfo["maxbuy"];
109
+					$g["seckillselfcount"] = $seckillinfo["selfcount"];
110
+					$g["seckillprice"] = $seckillinfo["price"];
111
+					$g["seckilltag"] = $seckillinfo["tag"];
112
+					$g["seckilllast"] = $seckilllast;
113
+				}
114
+				else 
115
+				{
116
+					$totalprice += $g["marketprice"] * $g["total"];
117
+				}
118
+			}
119
+			$totalmaxbuy = $g["stock"];
120
+			if( $seckillinfo && $seckillinfo["status"] == 0 ) 
121
+			{
122
+				if( $g["seckilllast"] < $totalmaxbuy ) 
123
+				{
124
+					$totalmaxbuy = $g["seckilllast"];
125
+				}
126
+				if( $totalmaxbuy < $g["total"] ) 
127
+				{
128
+					$g["total"] = $totalmaxbuy;
129
+				}
130
+				$g["minbuy"] = 0;
131
+			}
132
+			else 
133
+			{
134
+				if( $g["type"] == 4 ) 
135
+				{
136
+				}
137
+				else 
138
+				{
139
+					if( 0 < $g["maxbuy"] ) 
140
+					{
141
+						if( $totalmaxbuy != -1 ) 
142
+						{
143
+							if( $g["maxbuy"] < $totalmaxbuy ) 
144
+							{
145
+								$totalmaxbuy = $g["maxbuy"];
146
+							}
147
+						}
148
+						else 
149
+						{
150
+							$totalmaxbuy = $g["maxbuy"];
151
+						}
152
+					}
153
+					if( 0 < $g["usermaxbuy"] ) 
154
+					{
155
+						$order_goodscount = pdo_fetchcolumn("select ifnull(sum(og.total),0)  from " . tablename("ewei_shop_order_goods") . " og " . " left join " . tablename("ewei_shop_order") . " o on og.orderid=o.id " . " where og.goodsid=:goodsid and  o.status>=1 and o.openid=:openid  and og.uniacid=:uniacid ", array( ":goodsid" => $g["goodsid"], ":uniacid" => $uniacid, ":openid" => $openid ));
156
+						$last = $g["usermaxbuy"] - $order_goodscount;
157
+						if( $last <= 0 ) 
158
+						{
159
+							$last = 0;
160
+						}
161
+						if( $totalmaxbuy != -1 ) 
162
+						{
163
+							if( $last < $totalmaxbuy ) 
164
+							{
165
+								$totalmaxbuy = $last;
166
+							}
167
+						}
168
+						else 
169
+						{
170
+							$totalmaxbuy = $last;
171
+						}
172
+					}
173
+					if( 0 < $g["minbuy"] && $totalmaxbuy < $g["minbuy"] ) 
174
+					{
175
+						$g["minbuy"] = $totalmaxbuy;
176
+					}
177
+				}
178
+			}
179
+			$g["totalmaxbuy"] = $totalmaxbuy;
180
+			$g["unit"] = (empty($data["unit"]) ? "件" : $data["unit"]);
181
+			$g["productprice"] = price_format($g["productprice"]);
182
+			if( empty($g["selected"]) ) 
183
+			{
184
+				$ischeckall = false;
185
+			}
186
+		}
187
+		unset($g);
188
+		$list = set_medias($list, "thumb");
189
+		$merch_user = array( );
190
+		$merch = array( );
191
+		$merch_plugin = p("merch");
192
+		$merch_data = m("common")->getPluginset("merch");
193
+		if( $merch_plugin && $merch_data["is_openmerch"] ) 
194
+		{
195
+			$getListUser = $merch_plugin->getListUser($list);
196
+			$merch_user = $getListUser["merch_user"];
197
+			$merch = $getListUser["merch"];
198
+		}
199
+		if( empty($list) ) 
200
+		{
201
+			$list = array( );
202
+		}
203
+		else 
204
+		{
205
+			foreach( $list as $g ) 
206
+			{
207
+				$goodsmerchid = $g["merchid"];
208
+				if( !isset($merch_user[$goodsmerchid]) ) 
209
+				{
210
+					$merch_user[$goodsmerchid] = array( "goods_count" => 0, "goods_selected" => 0 );
211
+				}
212
+				$merch_user[$goodsmerchid]["goods_count"] = intval($merch_user[$goodsmerchid]["goods_count"]);
213
+				$merch_user[$goodsmerchid]["goods_selected"] = intval($merch_user[$goodsmerchid]["goods_selected"]);
214
+				$merch_user[$goodsmerchid]["goods_count"]++;
215
+				if( !empty($g["selected"]) ) 
216
+				{
217
+					$merch_user[$goodsmerchid]["goods_selected"]++;
218
+				}
219
+			}
220
+			foreach( $merch_user as $merchid => $merchuser ) 
221
+			{
222
+				if( !isset($merchuser["goods_selected"]) || !isset($merchuser["goods_count"]) ) 
223
+				{
224
+					continue;
225
+				}
226
+				if( $merchuser["goods_selected"] == $merchuser["goods_count"] ) 
227
+				{
228
+					$merch_user[$merchid]["selectedall"] = 1;
229
+				}
230
+				else 
231
+				{
232
+					$merch_user[$merchid]["selectedall"] = 0;
233
+				}
234
+			}
235
+		}
236
+		show_json(1, array( "ischeckall" => $ischeckall, "list" => $list, "total" => $total, "totalprice" => round($totalprice, 2), "merch_user" => $merch_user, "merch" => $merch ));
237
+	}
238
+	public function select() 
239
+	{
240
+		global $_W;
241
+		global $_GPC;
242
+		$id = intval($_GPC["id"]);
243
+		$select = intval($_GPC["select"]);
244
+		if( !empty($id) ) 
245
+		{
246
+			$data = pdo_fetch("select id,goodsid,optionid, total from " . tablename("ewei_shop_member_cart") . " " . " where id=:id and uniacid=:uniacid and openid=:openid limit 1 ", array( ":id" => $id, ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] ));
247
+			if( !empty($data) ) 
248
+			{
249
+				pdo_update("ewei_shop_member_cart", array( "selected" => $select ), array( "id" => $id, "uniacid" => $_W["uniacid"] ));
250
+			}
251
+		}
252
+		else 
253
+		{
254
+			pdo_update("ewei_shop_member_cart", array( "selected" => $select ), array( "uniacid" => $_W["uniacid"], "openid" => $_W["openid"] ));
255
+		}
256
+		show_json(1);
257
+	}
258
+	public function update() 
259
+	{
260
+		global $_W;
261
+		global $_GPC;
262
+		$id = intval($_GPC["id"]);
263
+		$goodstotal = intval($_GPC["total"]);
264
+		$optionid = intval($_GPC["optionid"]);
265
+		$type = intval($_GPC["type"]);
266
+		if( $type == 0 ) 
267
+		{
268
+			return NULL;
269
+		}
270
+		if( empty($goodstotal) ) 
271
+		{
272
+			$goodstotal = 1;
273
+		}
274
+		$data = pdo_fetch("select id,goodsid,optionid, total from " . tablename("ewei_shop_member_cart") . " " . " where id=:id and uniacid=:uniacid and openid=:openid limit 1 ", array( ":id" => $id, ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] ));
275
+		if( empty($data) ) 
276
+		{
277
+			show_json(0, "无购物车记录");
278
+		}
279
+		$goods = pdo_fetch("select id,maxbuy,minbuy,total,unit from " . tablename("ewei_shop_goods") . " where id=:id and uniacid=:uniacid and status=1 and deleted=0", array( ":id" => $data["goodsid"], ":uniacid" => $_W["uniacid"] ));
280
+		if( empty($goods) ) 
281
+		{
282
+			show_json(0, "商品未找到");
283
+		}
284
+		pdo_update("ewei_shop_member_cart", array( "total" => $goodstotal, "optionid" => $optionid ), array( "id" => $id, "uniacid" => $_W["uniacid"], "openid" => $_W["openid"] ));
285
+		$seckillinfo = plugin_run("seckill::getSeckill", $data["goodsid"], $data["optionid"], true, $_W["openid"]);
286
+		if( $seckillinfo && $seckillinfo["status"] == 0 ) 
287
+		{
288
+			$g = array( );
289
+			$g["seckillmaxbuy"] = $seckillinfo["maxbuy"];
290
+			$g["seckillselfcount"] = $seckillinfo["selfcount"];
291
+			$g["seckillprice"] = $seckillinfo["price"];
292
+			show_json(1, array( "seckillinfo" => $g ));
293
+		}
294
+		show_json(1);
295
+	}
296
+	public function add() 
297
+	{
298
+		global $_W;
299
+		global $_GPC;
300
+		$id = intval($_GPC["id"]);
301
+		$total = intval($_GPC["total"]);
302
+		//修复无法添加购物车
303
+		$this->_validateCartOverLimit();
304
+		($total <= 0) && ($total = 1);
305
+		$optionid = intval($_GPC['optionid']);
306
+		$goods = pdo_fetch("select id,marketprice,diyformid,diyformtype,diyfields, isverify, `type`,merchid, cannotrefund,hasoption from " . tablename("ewei_shop_goods") . " where id=:id and uniacid=:uniacid limit 1", array( ":id" => $id, ":uniacid" => $_W["uniacid"] ));
307
+		if( empty($goods) ) 
308
+		{
309
+			show_json(0, "商品未找到");
310
+		}
311
+		if( 0 < $goods["hasoption"] && empty($optionid) ) 
312
+		{
313
+			show_json(0, "请选择规格");
314
+		}
315
+		$member = m("member")->getMember($_W["openid"]);
316
+		if( !empty($_W["shopset"]["wap"]["open"]) && !empty($_W["shopset"]["wap"]["mustbind"]) && empty($member["mobileverify"]) ) 
317
+		{
318
+			show_json(0, array( "message" => "请先绑定手机", "url" => mobileUrl("member/bind", NULL, true) ));
319
+		}
320
+		if( $goods["isverify"] == 2 || $goods["type"] == 2 || $goods["type"] == 3 || !empty($goods["cannotrefund"]) ) 
321
+		{
322
+			show_json(0, "此商品不可加入购物车<br>请直接点击立刻购买");
323
+		}
324
+		$giftid = intval($_GPC["giftid"]);
325
+		$gift = pdo_fetch("select * from " . tablename("ewei_shop_gift") . " where uniacid = " . $_W["uniacid"] . " and id = " . $giftid . " and starttime >= " . time() . " and endtime <= " . time() . " and status = 1 ");
326
+		$diyform_plugin = p("diyform");
327
+		$diyformid = 0;
328
+		$diyformfields = iserializer(array( ));
329
+		$diyformdata = iserializer(array( ));
330
+		if( $diyform_plugin ) 
331
+		{
332
+			$diyformdata = $_GPC["diyformdata"];
333
+			if( !empty($diyformdata) && is_array($diyformdata) ) 
334
+			{
335
+				$diyformfields = false;
336
+				if( $goods["diyformtype"] == 1 ) 
337
+				{
338
+					$diyformid = intval($goods["diyformid"]);
339
+					$formInfo = $diyform_plugin->getDiyformInfo($diyformid);
340
+					if( !empty($formInfo) ) 
341
+					{
342
+						$diyformfields = $formInfo["fields"];
343
+					}
344
+				}
345
+				else 
346
+				{
347
+					if( $goods["diyformtype"] == 2 ) 
348
+					{
349
+						$diyformfields = iunserializer($goods["diyfields"]);
350
+					}
351
+				}
352
+				if( !empty($diyformfields) ) 
353
+				{
354
+					$insert_data = $diyform_plugin->getInsertData($diyformfields, $diyformdata);
355
+					$diyformdata = $insert_data["data"];
356
+					$diyformfields = iserializer($diyformfields);
357
+				}
358
+			}
359
+		}
360
+		$data = pdo_fetch("select id,total,diyformid from " . tablename("ewei_shop_member_cart") . " where goodsid=:id and openid=:openid and   optionid=:optionid  and deleted=0 and  uniacid=:uniacid   limit 1", array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"], ":optionid" => $optionid, ":id" => $id ));
361
+		if( empty($data) ) 
362
+		{
363
+			$data = array( "uniacid" => $_W["uniacid"], "merchid" => $goods["merchid"], "openid" => $_W["openid"], "goodsid" => $id, "optionid" => $optionid, "marketprice" => $goods["marketprice"], "total" => $total, "selected" => 1, "diyformid" => $diyformid, "diyformdata" => $diyformdata, "diyformfields" => $diyformfields, "createtime" => time() );
364
+			pdo_insert("ewei_shop_member_cart", $data);
365
+		}
366
+		else 
367
+		{
368
+			$data["diyformid"] = $diyformid;
369
+			$data["diyformdata"] = $diyformdata;
370
+			$data["diyformfields"] = $diyformfields;
371
+			$data["total"] += $total;
372
+			pdo_update("ewei_shop_member_cart", $data, array( "id" => $data["id"] ));
373
+		}
374
+		$cartcount = pdo_fetchcolumn("select sum(total) from " . tablename("ewei_shop_member_cart") . " where openid=:openid and deleted=0 and uniacid=:uniacid limit 1", array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] ));
375
+		show_json(1, array( "isnew" => false, "cartcount" => $cartcount, "goodsid" => $id ));
376
+	}
377
+	public function addwholesale() 
378
+	{
379
+		global $_W;
380
+		global $_GPC;
381
+		$id = intval($_GPC["id"]);
382
+		$optionsjson = $_GPC["options"];
383
+		$optionsdata = json_decode(htmlspecialchars_decode($optionsjson, ENT_QUOTES), true);
384
+		$this->_validateCartOverLimit();
385
+		$goods = pdo_fetch("select id,marketprice,diyformid,diyformtype,diyfields, isverify, `type`,merchid, cannotrefund from " . tablename("ewei_shop_goods") . " where id=:id and uniacid=:uniacid limit 1", array( ":id" => $id, ":uniacid" => $_W["uniacid"] ));
386
+		if( empty($goods) ) 
387
+		{
388
+			show_json(0, "商品未找到");
389
+		}
390
+		$member = m("member")->getMember($_W["openid"]);
391
+		if( !empty($_W["shopset"]["wap"]["open"]) && !empty($_W["shopset"]["wap"]["mustbind"]) && empty($member["mobileverify"]) ) 
392
+		{
393
+			show_json(0, array( "message" => "请先绑定手机", "url" => mobileUrl("member/bind", NULL, true) ));
394
+		}
395
+		foreach( $optionsdata as $option ) 
396
+		{
397
+			if( empty($option["total"]) ) 
398
+			{
399
+				continue;
400
+			}
401
+			$data = pdo_fetch("select id,total,diyformid from " . tablename("ewei_shop_member_cart") . " where goodsid=:id and openid=:openid and   optionid=:optionid  and deleted=0 and  uniacid=:uniacid   limit 1", array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"], ":optionid" => $option["optionid"], ":id" => $id ));
402
+			if( empty($data) ) 
403
+			{
404
+				$data = array( "uniacid" => $_W["uniacid"], "merchid" => $goods["merchid"], "openid" => $_W["openid"], "goodsid" => $id, "optionid" => $option["optionid"], "marketprice" => $goods["marketprice"], "total" => intval($option["total"]), "selected" => 1, "createtime" => time() );
405
+				pdo_insert("ewei_shop_member_cart", $data);
406
+			}
407
+			else 
408
+			{
409
+				$data["total"] += intval($option["total"]);
410
+				pdo_update("ewei_shop_member_cart", $data, array( "id" => $data["id"] ));
411
+			}
412
+		}
413
+		$cartcount = pdo_fetchcolumn("select sum(total) from " . tablename("ewei_shop_member_cart") . " where openid=:openid and deleted=0 and uniacid=:uniacid limit 1", array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] ));
414
+		show_json(1, array( "isnew" => false, "cartcount" => $cartcount ));
415
+	}
416
+	private function _validateCartOverLimit() 
417
+	{
418
+		global $_W;
419
+		global $_GPC;
420
+		$listCount = pdo_fetch("select count(*) sum from" . tablename("ewei_shop_member_cart") . " where uniacid = :uniacid and openid = :openid and deleted = 0", array( "uniacid" => $_W["uniacid"], "openid" => $_W["openid"] ));
421
+		$listCount = (empty($listCount["sum"]) ? 0 : $listCount["sum"]);
422
+		$wholesaleCount = 0;
423
+		$simpleGoodsCount = 1;
424
+		if( isset($_GPC["options"]) ) 
425
+		{
426
+			$optionsdata = json_decode(htmlspecialchars_decode($_GPC["options"], ENT_QUOTES), true);
427
+			foreach( $optionsdata as $item ) 
428
+			{
429
+				if( !empty($item["total"]) ) 
430
+				{
431
+					$wholesaleCount++;
432
+				}
433
+			}
434
+		}
435
+		if( 50 < $listCount + $simpleGoodsCount + $wholesaleCount ) 
436
+		{
437
+			show_json(0, "您的购物车宝贝超过50个了,建议您先去结算或清理");
438
+		}
439
+	}
440
+	public function remove() 
441
+	{
442
+		global $_W;
443
+		global $_GPC;
444
+		$ids = $_GPC["ids"];
445
+		if( empty($ids) || !is_array($ids) ) 
446
+		{
447
+			show_json(0, "参数错误");
448
+		}
449
+		$sql = "update " . tablename("ewei_shop_member_cart") . " set deleted=1 where uniacid=:uniacid and openid=:openid and id in (" . implode(",", $ids) . ")";
450
+		pdo_query($sql, array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] ));
451
+		show_json(1);
452
+	}
453
+	public function tofavorite() 
454
+	{
455
+		global $_W;
456
+		global $_GPC;
457
+		$uniacid = $_W["uniacid"];
458
+		$openid = $_W["openid"];
459
+		$ids = $_GPC["ids"];
460
+		if( empty($ids) || !is_array($ids) ) 
461
+		{
462
+			show_json(0, "参数错误");
463
+		}
464
+		foreach( $ids as $id ) 
465
+		{
466
+			$goodsid = pdo_fetchcolumn("select goodsid from " . tablename("ewei_shop_member_cart") . " where id=:id and uniacid=:uniacid and openid=:openid limit 1 ", array( ":id" => $id, ":uniacid" => $uniacid, ":openid" => $openid ));
467
+			if( !empty($goodsid) ) 
468
+			{
469
+				$fav = pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_member_favorite") . " where goodsid=:goodsid and uniacid=:uniacid and openid=:openid and deleted=0 limit 1 ", array( ":goodsid" => $goodsid, ":uniacid" => $uniacid, ":openid" => $openid ));
470
+				if( $fav <= 0 ) 
471
+				{
472
+					$fav = array( "uniacid" => $uniacid, "goodsid" => $goodsid, "openid" => $openid, "deleted" => 0, "createtime" => time() );
473
+					pdo_insert("ewei_shop_member_favorite", $fav);
474
+				}
475
+			}
476
+		}
477
+		$sql = "update " . tablename("ewei_shop_member_cart") . " set deleted=1 where uniacid=:uniacid and openid=:openid and id in (" . implode(",", $ids) . ")";
478
+		pdo_query($sql, array( ":uniacid" => $uniacid, ":openid" => $openid ));
479
+		show_json(1);
480
+	}
481
+	public function caculategoodsprice() 
482
+	{
483
+		global $_W;
484
+		global $_GPC;
485
+		$goods = $_GPC["goods"];
486
+		$goods = m("goods")->wholesaleprice($goods);
487
+		$cartgoods = array( );
488
+		foreach( $goods as $g ) 
489
+		{
490
+			$cartgoods[$g["id"]] = $g;
491
+		}
492
+		show_json(1, array( "goods" => $cartgoods ));
493
+	}
494
+	public function submit() 
495
+	{
496
+		global $_W;
497
+		global $_GPC;
498
+		$uniacid = $_W["uniacid"];
499
+		$openid = $_W["openid"];
500
+		$member = m("member")->getMember($openid);
501
+		$condition = " and f.uniacid= :uniacid and f.openid=:openid and f.selected=1 and f.deleted=0 ";
502
+		$params = array( ":uniacid" => $uniacid, ":openid" => $openid );
503
+		$sql = "SELECT f.id,f.total,f.goodsid,g.total as stock, o.stock as optionstock, g.hasoption,g.maxbuy,g.title,g.thumb,ifnull(o.marketprice, g.marketprice) as marketprice," . " g.productprice,o.title as optiontitle,f.optionid,o.specs,g.minbuy,g.maxbuy,g.usermaxbuy,g.unit,g.merchid,g.checked,g.isdiscount_discounts,g.isdiscount,g.isdiscount_time,g.isnodiscount,g.discounts,g.merchsale" . " ,f.selected,g.status,g.deleted as goodsdeleted,g.type,g.intervalfloor,g.intervalprice  FROM " . tablename("ewei_shop_member_cart") . " f " . " left join " . tablename("ewei_shop_goods") . " g on f.goodsid = g.id " . " left join " . tablename("ewei_shop_goods_option") . " o on f.optionid = o.id " . " where 1 " . $condition . " ORDER BY `id` DESC ";
504
+		$list = pdo_fetchall($sql, $params);
505
+		if( empty($list) ) 
506
+		{
507
+			show_json(0, "没有选择任何商品");
508
+		}
509
+		$list = m("goods")->wholesaleprice($list);
510
+		$array = pdo_fetchall("select og.optionid  from " . tablename("ewei_shop_order_goods") . " og " . " left join " . tablename("ewei_shop_order") . " o on og.orderid=o.id " . " where o.status>=1 and o.openid=:openid  and og.uniacid=:uniacid ", array( ":uniacid" => $uniacid, ":openid" => $openid ));
511
+		$t = 0;
512
+		foreach( $list as $key => $a ) 
513
+		{
514
+			foreach( $array as $k => $b ) 
515
+			{
516
+				if( $list["hasoption"] && $list["optionid"] == $array["optionid"] ) 
517
+				{
518
+					$t += 1;
519
+				}
520
+			}
521
+			$list[$key]["allt"] = $t;
522
+			$t = 0;
523
+		}
524
+		foreach( $list as &$g ) 
525
+		{
526
+			if( empty($g["unit"]) ) 
527
+			{
528
+				$g["unit"] = "件";
529
+			}
530
+			if( $g["status"] != 1 || $g["goodsdeleted"] == 1 ) 
531
+			{
532
+				show_json(0, $g["title"] . "<br/> 已经下架");
533
+			}
534
+			if( $g["type"] == 5 && 1 < count($list) ) 
535
+			{
536
+				show_json(0, $g["title"] . "<br/> 为记次商品,无法合并付款,请单独购买");
537
+			}
538
+			$seckillinfo = plugin_run("seckill::getSeckill", $g["goodsid"], $g["optionid"], true, $_W["openid"]);
539
+			if( !empty($g["optionid"]) ) 
540
+			{
541
+				$g["stock"] = $g["optionstock"];
542
+			}
543
+			if( $seckillinfo && $seckillinfo["status"] == 0 ) 
544
+			{
545
+				$check_buy = plugin_run("seckill::checkBuy", $seckillinfo, $g["title"], $g["unit"]);
546
+				if( is_error($check_buy) ) 
547
+				{
548
+					show_json(-1, $check_buy["message"]);
549
+				}
550
+			}
551
+			else 
552
+			{
553
+				$levelid = intval($member["level"]);
554
+				if( empty($member["groupid"]) ) 
555
+				{
556
+					$groupid = array( );
557
+				}
558
+				else 
559
+				{
560
+					$groupid = explode(",", $member["groupid"]);
561
+				}
562
+				if( $g["buylevels"] != "" ) 
563
+				{
564
+					$buylevels = explode(",", $g["buylevels"]);
565
+					if( !in_array($levelid, $buylevels) ) 
566
+					{
567
+						show_json(0, "您的会员等级无法购买<br/>" . $g["title"] . "!");
568
+					}
569
+				}
570
+				if( $g["buygroups"] != "" ) 
571
+				{
572
+					if( empty($groupid) ) 
573
+					{
574
+						$groupid[] = 0;
575
+					}
576
+					$buygroups = explode(",", $g["buygroups"]);
577
+					$intersect = array_intersect($groupid, $buygroups);
578
+					if( empty($intersect) ) 
579
+					{
580
+						show_json(0, "您所在会员组无法购买<br/>" . $g["title"] . "!");
581
+					}
582
+				}
583
+				if( $g["type"] == 4 ) 
584
+				{
585
+					if( $g["goodsalltotal"] < $g["minbuy"] ) 
586
+					{
587
+						show_json(0, $g["title"] . "<br/> " . $g["minbuy"] . $g["unit"] . "起批!");
588
+					}
589
+				}
590
+				else 
591
+				{
592
+					if( 0 < $g["minbuy"] && $g["total"] < $g["minbuy"] ) 
593
+					{
594
+						show_json(0, $g["title"] . "<br/> " . $g["minbuy"] . $g["unit"] . "起售!");
595
+					}
596
+					if( 0 < $g["maxbuy"] && $g["maxbuy"] < $g["total"] ) 
597
+					{
598
+						show_json(0, $g["title"] . "<br/> 一次限购 " . $g["maxbuy"] . $g["unit"] . "!");
599
+					}
600
+				}
601
+				if( 0 < $g["usermaxbuy"] ) 
602
+				{
603
+					if( $g["usermaxbuy"] < $g["total"] || $g["usermaxbuy"] < $g["allt"] ) 
604
+					{
605
+						show_json(0, $g["title"] . "<br/> 最多限购 " . $g["usermaxbuy"] . $g["unit"] . "!");
606
+					}
607
+					$order_goodscount = pdo_fetchcolumn("select ifnull(sum(og.total),0)  from " . tablename("ewei_shop_order_goods") . " og " . " left join " . tablename("ewei_shop_order") . " o on og.orderid=o.id " . " where og.goodsid=:goodsid and  o.status>=1 and o.openid=:openid  and og.uniacid=:uniacid ", array( ":goodsid" => $g["goodsid"], ":uniacid" => $uniacid, ":openid" => $openid ));
608
+					if( $g["usermaxbuy"] < $order_goodscount || $g["usermaxbuy"] < $order_goodscount + $g["allt"] ) 
609
+					{
610
+						show_json(0, $g["title"] . "<br/> 最多限购 " . $g["usermaxbuy"] . $g["unit"] . "!");
611
+					}
612
+					$total_buy = $order_goodscount + $g["total"];
613
+					if( $g["usermaxbuy"] < $total_buy || $g["usermaxbuy"] < $order_goodscount + $g["allt"] ) 
614
+					{
615
+						show_json(0, $g["title"] . "<br/> 最多限购 " . $g["usermaxbuy"] . $g["unit"] . "!");
616
+					}
617
+				}
618
+				if( !empty($optionid) ) 
619
+				{
620
+					$option = pdo_fetch("select id,title,marketprice,goodssn,productsn,stock,`virtual`,weight from " . tablename("ewei_shop_goods_option") . " where id=:id and goodsid=:goodsid and uniacid=:uniacid  limit 1", array( ":uniacid" => $uniacid, ":goodsid" => $goodsid, ":id" => $optionid ));
621
+					if( !empty($option) && $option["stock"] != -1 && empty($option["stock"]) ) 
622
+					{
623
+						show_json(-1, $g["title"] . "<br/>" . $option["title"] . " 库存不足!");
624
+					}
625
+				}
626
+				else 
627
+				{
628
+					if( $g["stock"] != -1 && empty($g["stock"]) ) 
629
+					{
630
+						show_json(0, $g["title"] . "<br/>库存不足!");
631
+					}
632
+				}
633
+			}
634
+		}
635
+		show_json(1);
636
+	}
637
+}
638
+?>

+ 72 - 0
addons/ewei_shopv2/core/mobile/member/changepwd.php Parādīt failu

@@ -0,0 +1,72 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Changepwd_EweiShopV2Page extends MobileLoginPage
7
+{
8
+	protected $member;
9
+
10
+	public function __construct()
11
+	{
12
+		global $_W;
13
+		global $_GPC;
14
+		parent::__construct();
15
+		$this->member = m('member')->getMember($_W['openid']);
16
+	}
17
+
18
+	public function main()
19
+	{
20
+		global $_W;
21
+		global $_GPC;
22
+		$member = $this->member;
23
+		$wapset = m('common')->getSysset('wap');
24
+		if (is_weixin() || empty($_GPC['__ewei_shopv2_member_session_' . $_W['uniacid']])) {
25
+			header('location: ' . mobileUrl());
26
+		}
27
+
28
+		if ($_W['ispost']) {
29
+			$mobile = trim($_GPC['mobile']);
30
+			$verifycode = trim($_GPC['verifycode']);
31
+			$pwd = trim($_GPC['pwd']);
32
+			@session_start();
33
+			$key = '__ewei_shopv2_member_verifycodesession_' . $_W['uniacid'] . '_' . $mobile;
34
+			if (!isset($_SESSION[$key]) || $_SESSION[$key] !== $verifycode || !isset($_SESSION['verifycodesendtime']) || $_SESSION['verifycodesendtime'] + 600 < time()) {
35
+				show_json(0, '验证码错误或已过期!');
36
+			}
37
+
38
+			$member = pdo_fetch('select id,openid,mobile,pwd,salt,credit1,credit2, createtime from ' . tablename('ewei_shop_member') . ' where mobile=:mobile and uniacid=:uniacid and mobileverify=1 limit 1', array(':mobile' => $mobile, ':uniacid' => $_W['uniacid']));
39
+			$salt = empty($member) ? '' : $member['salt'];
40
+
41
+			if (empty($salt)) {
42
+				$salt = random(16);
43
+
44
+				while (1) {
45
+					$count = pdo_fetchcolumn('select count(*) from ' . tablename('ewei_shop_member') . ' where salt=:salt limit 1', array(':salt' => $salt));
46
+
47
+					if ($count <= 0) {
48
+						break;
49
+					}
50
+
51
+					$salt = random(16);
52
+				}
53
+			}
54
+
55
+			pdo_update('ewei_shop_member', array('mobile' => $mobile, 'pwd' => md5($pwd . $salt), 'salt' => $salt, 'mobileverify' => 1), array('id' => $this->member['id'], 'uniacid' => $_W['uniacid']));
56
+			unset($_SESSION[$key]);
57
+			show_json(1);
58
+		}
59
+
60
+		$sendtime = $_SESSION['verifycodesendtime'];
61
+		if (empty($sendtime) || $sendtime + 60 < time()) {
62
+			$endtime = 0;
63
+		}
64
+		else {
65
+			$endtime = 60 - (time() - $sendtime);
66
+		}
67
+
68
+		include $this->template();
69
+	}
70
+}
71
+
72
+?>

+ 93 - 0
addons/ewei_shopv2/core/mobile/member/favorite.php Parādīt failu

@@ -0,0 +1,93 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Favorite_EweiShopV2Page extends MobileLoginPage
7
+{
8
+	public function main()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		include $this->template();
13
+	}
14
+
15
+	public function get_list()
16
+	{
17
+		global $_W;
18
+		global $_GPC;
19
+		$merch_plugin = p('merch');
20
+		$merch_data = m('common')->getPluginset('merch');
21
+		$pindex = max(1, intval($_GPC['page']));
22
+		$psize = 10;
23
+		$condition = ' and f.uniacid = :uniacid and f.openid=:openid and f.deleted=0';
24
+		if ($merch_plugin && $merch_data['is_openmerch']) {
25
+			$condition = ' and f.uniacid = :uniacid and f.openid=:openid and f.deleted=0 and f.type=0';
26
+		}
27
+
28
+		$params = array(':uniacid' => $_W['uniacid'], ':openid' => $_W['openid']);
29
+		$sql = 'SELECT COUNT(*) FROM ' . tablename('ewei_shop_member_favorite') . (' f where 1 ' . $condition);
30
+		$total = pdo_fetchcolumn($sql, $params);
31
+		$list = array();
32
+
33
+		if (!empty($total)) {
34
+			$sql = 'SELECT f.id,f.goodsid,g.title,g.thumb,g.marketprice,g.productprice,g.merchid FROM ' . tablename('ewei_shop_member_favorite') . ' f ' . ' left join ' . tablename('ewei_shop_goods') . ' g on f.goodsid = g.id ' . ' where 1 ' . $condition . ' ORDER BY `id` DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
35
+			$list = pdo_fetchall($sql, $params);
36
+			$list = set_medias($list, 'thumb');
37
+			if (!empty($list) && $merch_plugin && $merch_data['is_openmerch']) {
38
+				$merch_user = $merch_plugin->getListUser($list, 'merch_user');
39
+
40
+				foreach ($list as &$row) {
41
+					$row['merchname'] = $merch_user[$row['merchid']]['merchname'] ? $merch_user[$row['merchid']]['merchname'] : $_W['shopset']['shop']['name'];
42
+				}
43
+
44
+				unset($row);
45
+			}
46
+		}
47
+
48
+		show_json(1, array('list' => $list, 'total' => $total, 'pagesize' => $psize));
49
+	}
50
+
51
+	public function toggle()
52
+	{
53
+		global $_W;
54
+		global $_GPC;
55
+		$id = intval($_GPC['id']);
56
+		$isfavorite = intval($_GPC['isfavorite']);
57
+		$goods = pdo_fetch('select * from ' . tablename('ewei_shop_goods') . ' where id=:id and uniacid=:uniacid limit 1', array(':id' => $id, ':uniacid' => $_W['uniacid']));
58
+
59
+		if (empty($goods)) {
60
+			show_json(0, '商品未找到');
61
+		}
62
+
63
+		$data = pdo_fetch('select id,deleted from ' . tablename('ewei_shop_member_favorite') . ' where uniacid=:uniacid and goodsid=:id and openid=:openid limit 1', array(':uniacid' => $_W['uniacid'], ':openid' => $_W['openid'], ':id' => $id));
64
+
65
+		if (empty($data)) {
66
+			if (!empty($isfavorite)) {
67
+				$data = array('uniacid' => $_W['uniacid'], 'goodsid' => $id, 'openid' => $_W['openid'], 'createtime' => time());
68
+				pdo_insert('ewei_shop_member_favorite', $data);
69
+			}
70
+		}
71
+		else {
72
+			pdo_update('ewei_shop_member_favorite', array('deleted' => $isfavorite ? 0 : 1), array('id' => $data['id'], 'uniacid' => $_W['uniacid']));
73
+		}
74
+
75
+		show_json(1, array('isfavorite' => $isfavorite == 1));
76
+	}
77
+
78
+	public function remove()
79
+	{
80
+		global $_W;
81
+		global $_GPC;
82
+		$ids = $_GPC['ids'];
83
+		if (empty($ids) || !is_array($ids)) {
84
+			show_json(0, '参数错误');
85
+		}
86
+
87
+		$sql = 'update ' . tablename('ewei_shop_member_favorite') . ' set deleted=1 where openid=:openid and id in (' . implode(',', $ids) . ')';
88
+		pdo_query($sql, array(':openid' => $_W['openid']));
89
+		show_json(1);
90
+	}
91
+}
92
+
93
+?>

+ 51 - 0
addons/ewei_shopv2/core/mobile/member/fullback.php Parādīt failu

@@ -0,0 +1,51 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Fullback_EweiShopV2Page extends MobileLoginPage
7
+{
8
+	public function main()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$_GPC['type'] = intval($_GPC['type']);
13
+		include $this->template();
14
+	}
15
+
16
+	public function get_list()
17
+	{
18
+		global $_W;
19
+		global $_GPC;
20
+		$isfullback = intval($_GPC['type']);
21
+		$pindex = max(1, intval($_GPC['page']));
22
+		$psize = 10;
23
+		$condition = ' and fl.openid=:openid and fl.uniacid=:uniacid and fl.isfullback=:isfullback';
24
+		$params = array(':uniacid' => $_W['uniacid'], ':openid' => $_W['openid'], ':isfullback' => $isfullback);
25
+		$list = array();
26
+		$list = pdo_fetchall('select fl.*,g.thumb,g.title,og.optionname from ' . tablename('ewei_shop_fullback_log') . " as fl\r\n            left join " . tablename('ewei_shop_goods') . " as g on g.id = fl.goodsid\r\n            left join " . tablename('ewei_shop_order_goods') . (" as og on og.orderid = fl.orderid and og.goodsid = fl.goodsid \r\n            where 1 " . $condition . ' group by fl.id order by fl.createtime desc LIMIT ') . ($pindex - 1) * $psize . ',' . $psize, $params);
27
+		$total = pdo_fetchcolumn('select count(1) from ' . tablename('ewei_shop_fullback_log') . (" as fl\r\n            where 1 " . $condition . ' order by fl.createtime desc '), $params);
28
+
29
+		foreach ($list as &$row) {
30
+			$row['createtime'] = date('Y/m/d H:i:s', $row['createtime']);
31
+			$row['price'] = price_format($row['price'], 2);
32
+			$row['priceevery'] = price_format($row['priceevery'], 2);
33
+
34
+			if ($row['fullbackday'] < $row['day']) {
35
+				$row['surplusday'] = $row['day'] - $row['fullbackday'];
36
+				$row['surplusprice'] = $row['priceevery'] * $row['fullbackday'];
37
+			}
38
+			else {
39
+				$row['surplusday'] = 0;
40
+				$row['surplusprice'] = $row['price'];
41
+			}
42
+
43
+			$row = set_medias($row, array('thumb'));
44
+		}
45
+
46
+		unset($row);
47
+		show_json(1, array('list' => $list, 'total' => $total, 'pagesize' => $psize));
48
+	}
49
+}
50
+
51
+?>

+ 65 - 0
addons/ewei_shopv2/core/mobile/member/history.php Parādīt failu

@@ -0,0 +1,65 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class History_EweiShopV2Page extends MobileLoginPage
7
+{
8
+	public function main()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$merch_plugin = p('merch');
13
+		$merch_data = m('common')->getPluginset('merch');
14
+		if ($merch_plugin && $merch_data['is_openmerch']) {
15
+			include $this->template('merch/member/history');
16
+		}
17
+		else {
18
+			include $this->template();
19
+		}
20
+	}
21
+
22
+	public function get_list()
23
+	{
24
+		global $_W;
25
+		global $_GPC;
26
+		$pindex = max(1, intval($_GPC['page']));
27
+		$psize = 10;
28
+		$condition = ' and f.uniacid = :uniacid and f.openid=:openid and f.deleted=0';
29
+		$params = array(':uniacid' => $_W['uniacid'], ':openid' => $_W['openid']);
30
+		$sql = 'SELECT COUNT(*) FROM ' . tablename('ewei_shop_member_history') . (' f where 1 ' . $condition);
31
+		$total = pdo_fetchcolumn($sql, $params);
32
+		$sql = 'SELECT f.id,f.goodsid,g.title,g.thumb,g.marketprice,g.productprice,f.createtime,g.merchid FROM ' . tablename('ewei_shop_member_history') . ' f ' . ' left join ' . tablename('ewei_shop_goods') . ' g on f.goodsid = g.id ' . ' where 1 ' . $condition . ' ORDER BY `id` DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
33
+		$list = pdo_fetchall($sql, $params);
34
+		$merch_plugin = p('merch');
35
+		$merch_data = m('common')->getPluginset('merch');
36
+		if (!empty($list) && $merch_plugin && $merch_data['is_openmerch']) {
37
+			$merch_user = $merch_plugin->getListUser($list, 'merch_user');
38
+		}
39
+
40
+		foreach ($list as &$row) {
41
+			$row['createtime'] = date('Y-m-d H:i:s', $row['createtime']);
42
+			$row['thumb'] = tomedia($row['thumb']);
43
+			$row['merchname'] = $merch_user[$row['merchid']]['merchname'] ? $merch_user[$row['merchid']]['merchname'] : $_W['shopset']['shop']['name'];
44
+		}
45
+
46
+		unset($row);
47
+		show_json(1, array('list' => $list, 'total' => $total, 'pagesize' => $psize));
48
+	}
49
+
50
+	public function remove()
51
+	{
52
+		global $_W;
53
+		global $_GPC;
54
+		$ids = $_GPC['ids'];
55
+		if (empty($ids) || !is_array($ids)) {
56
+			show_json(0, '参数错误');
57
+		}
58
+
59
+		$sql = 'update ' . tablename('ewei_shop_member_history') . ' set deleted=1 where openid=:openid and id in (' . implode(',', $ids) . ')';
60
+		pdo_query($sql, array(':openid' => $_W['openid']));
61
+		show_json(1);
62
+	}
63
+}
64
+
65
+?>

+ 205 - 0
addons/ewei_shopv2/core/mobile/member/index.php Parādīt failu

@@ -0,0 +1,205 @@
1
+<?php  if( !defined("IN_IA") ) 
2
+{
3
+	exit( "Access Denied" );
4
+}
5
+class Index_EweiShopV2Page extends MobileLoginPage 
6
+{
7
+	public function main() 
8
+	{
9
+		global $_W;
10
+		global $_GPC;
11
+		$usermembercard = false;
12
+		$member = m("member")->getMember($_W["openid"], true);
13
+		if( p("membercard") && m("plugin")->permission("membercard") ) 
14
+		{
15
+			$list_membercard = p("membercard")->get_Mycard("", 0, 100);
16
+			$all_membercard = p("membercard")->get_Allcard(1, 100);
17
+			if( p("membercard") && $list_membercard["total"] <= 0 && $all_membercard["total"] <= 0 ) 
18
+			{
19
+				$usermembercard = false;
20
+			}
21
+			else 
22
+			{
23
+				$usermembercard = true;
24
+			}
25
+		}
26
+		$level = m("member")->getLevel($_W["openid"]);
27
+		if( com("wxcard") ) 
28
+		{
29
+			$wxcardupdatetime = intval($member["wxcardupdatetime"]);
30
+			if( $wxcardupdatetime + 86400 < time() ) 
31
+			{
32
+				com_run("wxcard::updateMemberCardByOpenid", $_W["openid"]);
33
+				pdo_update("ewei_shop_member", array( "wxcardupdatetime" => time() ), array( "openid" => $_W["openid"] ));
34
+			}
35
+		}
36
+		$this->diypage("member");
37
+		$open_creditshop = p("creditshop") && $_W["shopset"]["creditshop"]["centeropen"];
38
+		$params = array( ":uniacid" => $_W["uniacid"], ":openid" => $_W["openid"] );
39
+		$merch_plugin = p("merch");
40
+		$merch_data = m("common")->getPluginset("merch");
41
+		if( $merch_plugin && $merch_data["is_openmerch"] ) 
42
+		{
43
+			$statics = array( "order_0" => pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_order") . " where openid=:openid and status=0 and (isparent=1 or (isparent=0 and parentid=0)) and paytype<>3 and uniacid=:uniacid and istrade=0 and userdeleted=0", $params), "order_1" => pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_order") . " where openid=:openid and (status=1 or (status=0 and paytype=3)) and isparent=0 and refundid=0 and uniacid=:uniacid and istrade=0 and userdeleted=0", $params), "order_2" => pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_order") . " where openid=:openid and (status=2 or (status=1 and sendtype>0)) and isparent=0 and refundid=0 and uniacid=:uniacid and istrade=0 and userdeleted=0", $params), "order_4" => pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_order") . " where openid=:openid and refundstate=1 and isparent=0 and uniacid=:uniacid and istrade=0 and userdeleted=0", $params), "cart" => pdo_fetchcolumn("select ifnull(sum(total),0) from " . tablename("ewei_shop_member_cart") . " where uniacid=:uniacid and openid=:openid and deleted=0", $params), "favorite" => pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_member_favorite") . " where uniacid=:uniacid and openid=:openid and deleted=0", $params) );
44
+		}
45
+		else 
46
+		{
47
+			$statics = array( "order_0" => pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_order") . " where openid=:openid and ismr=0 and status=0 and isparent=0 and paytype<>3 and uniacid=:uniacid and istrade=0 and userdeleted=0", $params), "order_1" => pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_order") . " where openid=:openid and ismr=0 and (status=1 or (status=0 and paytype=3)) and isparent=0 and refundid=0 and uniacid=:uniacid and istrade=0 and userdeleted=0", $params), "order_2" => pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_order") . " where openid=:openid and ismr=0 and (status=2 or (status=1 and sendtype>0)) and isparent=0 and refundid=0 and uniacid=:uniacid and istrade=0 and userdeleted=0", $params), "order_4" => pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_order") . " where openid=:openid and ismr=0 and refundstate=1 and isparent=0 and uniacid=:uniacid and istrade=0 and userdeleted=0", $params), "order_5" => pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_order") . " where openid=:openid and ismr=0 and uniacid=:uniacid and iscycelbuy=1 and status in(0,1,2)", $params), "cart" => pdo_fetchcolumn("select ifnull(sum(total),0) from " . tablename("ewei_shop_member_cart") . " where uniacid=:uniacid and openid=:openid and deleted=0 and selected = 1", $params), "favorite" => ($merch_plugin && $merch_data["is_openmerch"] ? pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_member_favorite") . " where uniacid=:uniacid and openid=:openid and deleted=0 and `type`=0", $params) : pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_member_favorite") . " where uniacid=:uniacid and openid=:openid and deleted=0", $params)) );
48
+		}
49
+		$newstore_plugin = p("newstore");
50
+		if( $newstore_plugin ) 
51
+		{
52
+			$statics["norder_0"] = pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_order") . " where openid=:openid and ismr=0 and status=0 and isparent=0 and istrade=1 and uniacid=:uniacid", $params);
53
+			$statics["norder_1"] = pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_order") . " where openid=:openid and ismr=0 and status=1 and isparent=0 and istrade=1 and refundid=0 and uniacid=:uniacid", $params);
54
+			$statics["norder_3"] = pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_order") . " where openid=:openid and ismr=0 and status=3 and isparent=0 and istrade=1 and uniacid=:uniacid", $params);
55
+			$statics["norder_4"] = pdo_fetchcolumn("select count(*) from " . tablename("ewei_shop_order") . " where openid=:openid and ismr=0 and refundstate=1 and isparent=0 and istrade=1 and uniacid=:uniacid", $params);
56
+		}
57
+		$hascoupon = false;
58
+		$hascouponcenter = false;
59
+		$plugin_coupon = com("coupon");
60
+		if( $plugin_coupon ) 
61
+		{
62
+			$time = time();
63
+			$sql = "select count(*) from " . tablename("ewei_shop_coupon_data") . " d";
64
+			$sql .= " left join " . tablename("ewei_shop_coupon") . " c on d.couponid = c.id";
65
+			$sql .= " where d.openid=:openid and d.uniacid=:uniacid and  d.used=0 ";
66
+			$sql .= " and (   (c.timelimit = 0 and ( c.timedays=0 or c.timedays*86400 + d.gettime >=unix_timestamp() ) )  or  (c.timelimit =1 and c.timestart<=" . $time . " && c.timeend>=" . $time . ")) order by d.gettime desc";
67
+			$statics["coupon"] = pdo_fetchcolumn($sql, array( ":openid" => $_W["openid"], ":uniacid" => $_W["uniacid"] ));
68
+			$pcset = $_W["shopset"]["coupon"];
69
+			if( empty($pcset["closemember"]) ) 
70
+			{
71
+				$hascoupon = true;
72
+			}
73
+			if( empty($pcset["closecenter"]) ) 
74
+			{
75
+				$hascouponcenter = true;
76
+			}
77
+			if( $hascoupon ) 
78
+			{
79
+				$couponnum = com("coupon")->getCanGetCouponNum($_W["merchid"]);
80
+				$cardnum = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename("ewei_shop_wxcard") . " where  uniacid=:uniacid and gettype =1");
81
+				$cardnum += $cardnum;
82
+			}
83
+		}
84
+		$hasglobonus = false;
85
+		$plugin_globonus = p("globonus");
86
+		if( $plugin_globonus ) 
87
+		{
88
+			$plugin_globonus_set = $plugin_globonus->getSet();
89
+			$hasglobonus = !empty($plugin_globonus_set["open"]) && !empty($plugin_globonus_set["openmembercenter"]);
90
+		}
91
+		$haslive = false;
92
+		$haslive = p("live");
93
+		if( $haslive ) 
94
+		{
95
+			$live_set = $haslive->getSet();
96
+			$haslive = $live_set["ismember"];
97
+		}
98
+		$hasThreen = false;
99
+		$hasThreen = p("threen");
100
+		if( $hasThreen ) 
101
+		{
102
+			$plugin_threen_set = $hasThreen->getSet();
103
+			$hasThreen = !empty($plugin_threen_set["open"]) && !empty($plugin_threen_set["threencenter"]);
104
+		}
105
+		$hasauthor = false;
106
+		$plugin_author = p("author");
107
+		if( $plugin_author ) 
108
+		{
109
+			$plugin_author_set = $plugin_author->getSet();
110
+			$hasauthor = !empty($plugin_author_set["open"]) && !empty($plugin_author_set["openmembercenter"]);
111
+		}
112
+		$hasabonus = false;
113
+		$plugin_abonus = p("abonus");
114
+		if( $plugin_abonus ) 
115
+		{
116
+			$plugin_abonus_set = $plugin_abonus->getSet();
117
+			$hasabonus = !empty($plugin_abonus_set["open"]) && !empty($plugin_abonus_set["openmembercenter"]);
118
+		}
119
+		$card = m("common")->getSysset("membercard");
120
+		$actionset = m("common")->getSysset("memberCardActivation");
121
+		$haveverifygoods = m("verifygoods")->checkhaveverifygoods($_W["openid"]);
122
+		if( !empty($haveverifygoods) ) 
123
+		{
124
+			$verifygoods = m("verifygoods")->getCanUseVerifygoods($_W["openid"]);
125
+		}
126
+		$showcard = 0;
127
+		if( !empty($card) ) 
128
+		{
129
+			$membercardid = $member["membercardid"];
130
+			if( !empty($membercardid) && $card["card_id"] == $membercardid ) 
131
+			{
132
+				$cardtag = "查看微信会员卡信息";
133
+				$showcard = 1;
134
+			}
135
+			else 
136
+			{
137
+				if( !empty($actionset["centerget"]) ) 
138
+				{
139
+					$showcard = 1;
140
+					$cardtag = "领取微信会员卡";
141
+				}
142
+			}
143
+		}
144
+		$hasqa = false;
145
+		$plugin_qa = p("qa");
146
+		if( $plugin_qa ) 
147
+		{
148
+			$plugin_qa_set = $plugin_qa->getSet();
149
+			if( !empty($plugin_qa_set["showmember"]) ) 
150
+			{
151
+				$hasqa = true;
152
+			}
153
+		}
154
+		$hassign = false;
155
+		$com_sign = p("sign");
156
+		if( $com_sign ) 
157
+		{
158
+			$com_sign_set = $com_sign->getSet();
159
+			if( !empty($com_sign_set["iscenter"]) && !empty($com_sign_set["isopen"]) ) 
160
+			{
161
+				$hassign = (empty($_W["shopset"]["trade"]["credittext"]) ? "积分" : $_W["shopset"]["trade"]["credittext"]);
162
+				$hassign .= (empty($com_sign_set["textsign"]) ? "签到" : $com_sign_set["textsign"]);
163
+			}
164
+		}
165
+		$hasLineUp = false;
166
+		$lineUp = p("lineup");
167
+		if( $lineUp ) 
168
+		{
169
+			$lineUpSet = $lineUp->getSet();
170
+			if( !empty($lineUpSet["isopen"]) && !empty($lineUpSet["mobile_show"]) ) 
171
+			{
172
+				$hasLineUp = true;
173
+			}
174
+		}
175
+		$wapset = m("common")->getSysset("wap");
176
+		$appset = m("common")->getSysset("app");
177
+		$needbind = false;
178
+		if( (empty($member["mobileverify"]) || empty($member["mobile"])) && (empty($_W["shopset"]["app"]["isclose"]) && !empty($_W["shopset"]["app"]["openbind"]) || !empty($_W["shopset"]["wap"]["open"]) || $hasThreen) ) 
179
+		{
180
+			$needbind = true;
181
+		}
182
+		if( p("mmanage") ) 
183
+		{
184
+			$roleuser = pdo_fetch("SELECT id, uid, username, status FROM" . tablename("ewei_shop_perm_user") . "WHERE openid=:openid AND uniacid=:uniacid AND status=1 LIMIT 1", array( ":openid" => $_W["openid"], ":uniacid" => $_W["uniacid"] ));
185
+		}
186
+		$hasFullback = true;
187
+		$ishidden = m("common")->getSysset("fullback");
188
+		if( $ishidden["ishidden"] == true ) 
189
+		{
190
+			$hasFullback = false;
191
+		}
192
+		$hasdividend = false;
193
+		$plugin_dividend = p("dividend");
194
+		if( $plugin_dividend ) 
195
+		{
196
+			$plugin_dividend_set = $plugin_dividend->getSet();
197
+			if( !empty($plugin_dividend_set["open"]) && !empty($plugin_dividend_set["membershow"]) ) 
198
+			{
199
+				$hasdividend = true;
200
+			}
201
+		}
202
+		include($this->template());
203
+	}
204
+}
205
+?>

+ 132 - 0
addons/ewei_shopv2/core/mobile/member/info.php Parādīt failu

@@ -0,0 +1,132 @@
1
+<?php
2
+if (!(defined('IN_IA'))) 
3
+{
4
+	exit('Access Denied');
5
+}
6
+class Info_EweiShopV2Page extends MobileLoginPage 
7
+{
8
+	protected $member;
9
+	public function __construct() 
10
+	{
11
+		global $_W;
12
+		global $_GPC;
13
+		parent::__construct();
14
+		$this->member = m('member')->getInfo($_W['openid']);
15
+	}
16
+	protected function diyformData() 
17
+	{
18
+		$template_flag = 0;
19
+		$diyform_plugin = p('diyform');
20
+		if ($diyform_plugin) 
21
+		{
22
+			$set_config = $diyform_plugin->getSet();
23
+			$user_diyform_open = $set_config['user_diyform_open'];
24
+			if ($user_diyform_open == 1) 
25
+			{
26
+				$template_flag = 1;
27
+				$diyform_id = $set_config['user_diyform'];
28
+				if (!(empty($diyform_id))) 
29
+				{
30
+					$formInfo = $diyform_plugin->getDiyformInfo($diyform_id);
31
+					$fields = $formInfo['fields'];
32
+					$diyform_data = iunserializer($this->member['diymemberdata']);
33
+					$f_data = $diyform_plugin->getDiyformData($diyform_data, $fields, $this->member);
34
+				}
35
+			}
36
+		}
37
+		return array('template_flag' => $template_flag, 'set_config' => $set_config, 'diyform_plugin' => $diyform_plugin, 'formInfo' => $formInfo, 'diyform_id' => $diyform_id, 'diyform_data' => $diyform_data, 'fields' => $fields, 'f_data' => $f_data);
38
+	}
39
+	public function main() 
40
+	{
41
+		global $_W;
42
+		global $_GPC;
43
+		$diyform_data = $this->diyformData();
44
+		extract($diyform_data);
45
+		$returnurl = urldecode(trim($_GPC['returnurl']));
46
+		$member = $this->member;
47
+		$wapset = m('common')->getSysset('wap');
48
+		$area_set = m('util')->get_area_config_set();
49
+		$new_area = intval($area_set['new_area']);
50
+		$show_data = 1;
51
+		if ((!(empty($new_area)) && empty($member['datavalue'])) || (empty($new_area) && !(empty($member['datavalue'])))) 
52
+		{
53
+			$show_data = 0;
54
+		}
55
+		include $this->template();
56
+	}
57
+	public function submit() 
58
+	{
59
+		global $_W;
60
+		global $_GPC;
61
+		$diyform_data = $this->diyformData();
62
+		extract($diyform_data);
63
+		$memberdata = $_GPC['memberdata'];
64
+		if ($template_flag == 1) 
65
+		{
66
+			$data = array();
67
+			$m_data = array();
68
+			$mc_data = array();
69
+			$insert_data = $diyform_plugin->getInsertData($fields, $memberdata);
70
+			$data = $insert_data['data'];
71
+			$m_data = $insert_data['m_data'];
72
+			$mc_data = $insert_data['mc_data'];
73
+			$m_data['diymemberid'] = $diyform_id;
74
+			$m_data['diymemberfields'] = iserializer($fields);
75
+			$m_data['diymemberdata'] = $data;
76
+			unset($mc_data['credit1'], $m_data['credit2']);
77
+			if (!(empty($memberdata['edit_avatar']))) 
78
+			{
79
+				$m_data['avatar'] = $memberdata['edit_avatar'];
80
+			}
81
+			$m_data['nickname'] = $memberdata['nickname'];
82
+			pdo_update('ewei_shop_member', $m_data, array('openid' => $_W['openid'], 'uniacid' => $_W['uniacid']));
83
+			if (!(empty($this->member['uid']))) 
84
+			{
85
+				if (!(empty($mc_data))) 
86
+				{
87
+					unset($mc_data['credit1'], $mc_data['credit2']);
88
+					m('member')->mc_update($this->member['uid'], $mc_data);
89
+				}
90
+			}
91
+		}
92
+		else 
93
+		{
94
+			$arr = array('realname' => trim($memberdata['realname']), 'weixin' => trim($memberdata['weixin']), 'birthyear' => intval($memberdata['birthyear']), 'birthmonth' => intval($memberdata['birthmonth']), 'birthday' => intval($memberdata['birthday']), 'province' => trim($memberdata['province']), 'city' => trim($memberdata['city']), 'datavalue' => trim($memberdata['datavalue']), 'mobile' => trim($memberdata['mobile']), 'nickname' => trim($memberdata['nickname']), 'avatar' => trim($memberdata['avatar']));
95
+			if ((empty($_W['shopset']['app']['isclose']) && !(empty($_W['shopset']['app']['openbind']))) || !(empty($_W['shopset']['wap']['open']))) 
96
+			{
97
+				unset($arr['mobile']);
98
+			}
99
+			pdo_update('ewei_shop_member', $arr, array('openid' => $_W['openid'], 'uniacid' => $_W['uniacid']));
100
+			if (!(empty($this->member['uid']))) 
101
+			{
102
+				$mcdata = $_GPC['mcdata'];
103
+				unset($mcdata['credit1'], $mcdata['credit2']);
104
+				m('member')->mc_update($this->member['uid'], $mcdata);
105
+			}
106
+		}
107
+		show_json(1);
108
+	}
109
+	public function face() 
110
+	{
111
+		global $_W;
112
+		global $_GPC;
113
+		$member = $this->member;
114
+		if ($_W['ispost']) 
115
+		{
116
+			$nickname = trim($_GPC['nickname']);
117
+			$avatar = trim($_GPC['avatar']);
118
+			if (empty($nickname)) 
119
+			{
120
+				show_json(0, '请填写昵称');
121
+			}
122
+			if (empty($avatar)) 
123
+			{
124
+				show_json(0, '请上传头像');
125
+			}
126
+			pdo_update('ewei_shop_member', array('avatar' => $avatar, 'nickname' => $nickname), array('id' => $member['id'], 'uniacid' => $_W['uniacid']));
127
+			show_json(1);
128
+		}
129
+		include $this->template();
130
+	}
131
+}
132
+?>

+ 53 - 0
addons/ewei_shopv2/core/mobile/member/log.php Parādīt failu

@@ -0,0 +1,53 @@
1
+<?php
2
+
3
+if (!defined('IN_IA')) {
4
+    exit('Access Denied');
5
+}
6
+
7
+class Log_EweiShopV2Page extends MobileLoginPage {
8
+
9
+    function main() {
10
+        global $_W, $_GPC;
11
+        $_GPC['type'] = intval($_GPC['type']);
12
+        include $this->template();
13
+    }
14
+    function get_list(){
15
+        global $_W, $_GPC;
16
+        $type = intval($_GPC['type']);
17
+        $pindex = max(1, intval($_GPC['page']));
18
+        $psize = 10;
19
+        $apply_type = array(0 => '微信钱包', 2 => '支付宝', 3 => '银行卡');
20
+
21
+        $condition = " and openid=:openid and uniacid=:uniacid and type=:type";
22
+        $params = array(
23
+            ':uniacid' => $_W['uniacid'],
24
+            ':openid' => $_W['openid'],
25
+            ':type' => intval($_GPC['type'])
26
+        );
27
+        $uidinfo = M('member')->getInfo($_W['openid']);
28
+        $uid = $uidinfo['uid'];
29
+        //$credit_condition = " and r.uniacid=".$_W['uniacid']." and r.credittype='credit2' and r.uid = ".$uid." and r.num > 0 order by r.createtime desc LIMIT ";
30
+        $credit_condition = " and r.uniacid=".$_W['uniacid']." and r.credittype='credit2' and r.uid = ".$uid." and r.num > 0 and remark not like '%充值%' order by r.createtime desc LIMIT ";
31
+        if($uid>0){
32
+            $r = pdo_fetchall("select m.uid,m.mobile,m.nickname,r.remark title,r.num money,r.createtime from " . tablename("ewei_shop_member_credit_record") . "r left join ".tablename('ewei_shop_member')." m on m.uid = r.uid where 1 " . $credit_condition . ($pindex - 1) * $psize . ',' . $psize );
33
+            foreach($r as &$item) {
34
+                $item['createtime'] = date("Y-m-d H:i:s", $item['createtime']);
35
+                // 交易类型
36
+                $item['rechargetype'] = 'credit';
37
+            }
38
+            unset($item);
39
+        }
40
+        $list = pdo_fetchall("select * from " . tablename('ewei_shop_member_log') . " where 1 {$condition} order by createtime desc LIMIT " . ($pindex - 1) * $psize . ',' . $psize , $params);
41
+        $total = pdo_fetchcolumn('select count(*) from ' . tablename('ewei_shop_member_log') . " where 1 {$condition}", $params);
42
+        foreach ($list as &$row) {
43
+            $row['createtime'] = date('Y-m-d H:i', $row['createtime']);
44
+            $row['typestr'] = $apply_type[$row['applytype']];
45
+        }
46
+        unset($row);
47
+        if(is_array($r)){
48
+            $list = array_merge($r, $list);
49
+        }
50
+        show_json(1,array('list'=>$list,'total'=>$total,'pagesize'=>$psize));
51
+    }
52
+
53
+}

+ 47 - 0
addons/ewei_shopv2/core/mobile/member/notice.php Parādīt failu

@@ -0,0 +1,47 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Notice_EweiShopV2Page extends MobileLoginPage
7
+{
8
+	public function main()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$openid = $_W['openid'];
13
+		$uniacid = $_W['uniacid'];
14
+		$member = m('member')->getMember($openid);
15
+		$notice = iunserializer($member['noticeset']);
16
+		$hascommission = false;
17
+
18
+		if (p('commission')) {
19
+			$cset = p('commission')->getSet();
20
+			$hascommission = !empty($cset['level']);
21
+		}
22
+
23
+		if ($_W['ispost']) {
24
+			$type = trim($_GPC['type']);
25
+
26
+			if (empty($type)) {
27
+				show_json(0, '参数错误');
28
+			}
29
+
30
+			$checked = intval($_GPC['checked']);
31
+
32
+			if (empty($checked)) {
33
+				$notice[$type] = 1;
34
+			}
35
+			else {
36
+				unset($notice[$type]);
37
+			}
38
+
39
+			pdo_update('ewei_shop_member', array('noticeset' => iserializer($notice)), array('openid' => $openid, 'uniacid' => $uniacid));
40
+			show_json(1);
41
+		}
42
+
43
+		include $this->template();
44
+	}
45
+}
46
+
47
+?>

+ 188 - 0
addons/ewei_shopv2/core/mobile/member/rank.php Parādīt failu

@@ -0,0 +1,188 @@
1
+<?php  if( !defined("IN_IA") ) 
2
+{
3
+	exit( "Access Denied" );
4
+}
5
+class Rank_EweiShopV2Page extends MobileLoginPage 
6
+{
7
+	protected function status() 
8
+	{
9
+		global $_W;
10
+		if( empty($_W["shopset"]["rank"]["status"]) ) 
11
+		{
12
+			$err = "未开启积分排名";
13
+			if( $_W["isajax"] ) 
14
+			{
15
+				show_json(0, $err);
16
+			}
17
+			$this->message($err, "", "error");
18
+		}
19
+	}
20
+	protected function getRank($update = false) 
21
+	{
22
+		global $_W;
23
+		$rank_cache = m("cache")->getArray("member_rank");
24
+		if( empty($rank_cache) || $rank_cache["time"] < TIMESTAMP || $update ) 
25
+		{
26
+			$num = intval($_W["shopset"]["rank"]["num"]);
27
+			$result = pdo_fetchall("SELECT sm.id,sm.uid,m.credit1,sm.nickname,sm.avatar,sm.openid FROM " . tablename("ewei_shop_member") . " sm RIGHT JOIN " . tablename("mc_members") . " m ON m.uid=sm.uid WHERE sm.uniacid = :uniacid ORDER BY m.credit1 DESC LIMIT " . $num, array( ":uniacid" => $_W["uniacid"] ));
28
+			$result1 = pdo_fetchall("SELECT id,uid,credit1,nickname,avatar,openid FROM " . tablename("ewei_shop_member") . " WHERE uniacid = :uniacid AND uid=0 ORDER BY credit1 DESC LIMIT " . $num, array( ":uniacid" => $_W["uniacid"] ));
29
+			foreach( $result1 as $key => $value ) 
30
+			{
31
+				$result1[$key]["avatar"] = tomedia($value["avatar"]);
32
+			}
33
+			$result = array_merge($result, $result1);
34
+			usort($result, "ranksort");
35
+			$result = array_slice($result, 0, $num);
36
+			m("cache")->set("member_rank", array( "time" => TIMESTAMP + 3600, "result" => $result ));
37
+		}
38
+		return $rank_cache;
39
+	}
40
+	public function main() 
41
+	{
42
+		global $_W;
43
+		global $_GPC;
44
+		$this->status();
45
+		$user = m("member")->getMember($_W["openid"], true);
46
+		$rank_cache = $this->getRank();
47
+		$result = $rank_cache["result"];
48
+		$paiming = 0;
49
+		foreach( $result as $key => $val ) 
50
+		{
51
+			if( $val["openid"] == $_W["openid"] ) 
52
+			{
53
+				$paiming += $key + 1;
54
+			}
55
+		}
56
+		$num = intval($_W["shopset"]["rank"]["num"]);
57
+		$user["credit1"] = intval($user["credit1"]);
58
+		$user["paiming"] = (empty($paiming) ? "未上榜" : $paiming);
59
+		$seven = $this->creditChange($user["uid"], "credit1", 7, $_W["openid"]);
60
+		$user["seven"] = (empty($seven) ? 0 : $seven);
61
+		include($this->template());
62
+	}
63
+	public function ajaxpage() 
64
+	{
65
+		global $_W;
66
+		global $_GPC;
67
+		$this->status();
68
+		$pindex = max(1, (int) $_GPC["page"]);
69
+		$psize = 20;
70
+		$num = intval($_W["shopset"]["rank"]["num"]);
71
+		if( $num <= 0 ) 
72
+		{
73
+			$num = 50;
74
+		}
75
+		$stop = false;
76
+		if( $num <= $pindex * $psize ) 
77
+		{
78
+			$psize = ($num % $psize == 0 ? 20 : $num % $psize);
79
+			$pindex = ceil($num / $psize);
80
+			$stop = true;
81
+		}
82
+		$rank_cache = $this->getRank();
83
+		$result = $rank_cache["result"];
84
+		$result = array_slice($result, ($pindex - 1) * $psize, $psize);
85
+		show_json(1, array( "list" => $result, "stop" => $stop ));
86
+	}
87
+	protected function creditChange($uid, $credittype = "credit1", $day = 7, $openid = "") 
88
+	{
89
+		global $_W;
90
+		$day = (int) $day;
91
+		if( $day != 0 ) 
92
+		{
93
+			$createtime1 = strtotime(date("Y-m-d", time() - $day * 3600 * 24));
94
+			$createtime2 = strtotime(date("Y-m-d", time()));
95
+		}
96
+		else 
97
+		{
98
+			$createtime1 = strtotime(date("Y-m-d", time()));
99
+			$createtime2 = strtotime(date("Y-m-d", time() + 3600 * 24));
100
+		}
101
+		if( $uid ) 
102
+		{
103
+			$sql = "select sum(num) from " . tablename("mc_credits_record") . " where uniacid = :uniacid and uid = :uid and credittype = :credittype and `module` = \"ewei_shopv2\" and createtime between :createtime1 and :createtime2 and uid<>0";
104
+			$param = array( ":uniacid" => $_W["uniacid"], ":uid" => (int) $uid, ":createtime1" => $createtime1, ":createtime2" => $createtime2, ":credittype" => $credittype );
105
+		}
106
+		else 
107
+		{
108
+			$sql = "select sum(num) from " . tablename("ewei_shop_member_credit_record") . " where uniacid = :uniacid and openid = :openid and credittype = :credittype and createtime between :createtime1 and :createtime2";
109
+			$param = array( ":uniacid" => $_W["uniacid"], ":openid" => $openid, ":createtime1" => $createtime1, ":createtime2" => $createtime2, ":credittype" => $credittype );
110
+		}
111
+		return pdo_fetchcolumn($sql, $param);
112
+	}
113
+	protected function orderStatus() 
114
+	{
115
+		global $_W;
116
+		if( empty($_W["shopset"]["rank"]["order_status"]) ) 
117
+		{
118
+			$err = "未开启订单排名";
119
+			if( $_W["isajax"] ) 
120
+			{
121
+				show_json(0, $err);
122
+			}
123
+			$this->message($err, "", "error");
124
+		}
125
+	}
126
+	public function order_rank() 
127
+	{
128
+		global $_W;
129
+		global $_GPC;
130
+		$this->orderStatus();
131
+		$user = m("member")->getMember($_W["openid"], true);
132
+		$result_one = pdo_fetch("select a.openid, sum(price) as price,a.uniacid,a.status\r\n\t\t\tfrom (\r\n\t\t\t(select openid, sum(price) price,uniacid,status from " . tablename("ewei_shop_order") . " where uniacid = :uniacid and status = 1 group by openid)\r\n\t\t\tunion  all (select openid, sum(price+freight) price,uniacid,status from " . tablename("ewei_shop_groups_order") . " where uniacid = :uniacid and status >= 1 group by openid)\r\n\t\t\t) a where a.openid = :openid group by a.openid ", array( ":uniacid" => $_W["uniacid"], ":openid" => $user["openid"] ));
133
+		$result_all = pdo_fetchall("select a.openid, sum(price) as price,a.uniacid,a.status\r\n\t\t\tfrom (\r\n\t\t\t(select openid, sum(price) price,uniacid,status from " . tablename("ewei_shop_order") . " where uniacid = :uniacid and status = 1 group by openid)\r\n\t\t\tunion  all (select openid, sum(price+freight) price,uniacid,status from " . tablename("ewei_shop_groups_order") . " where uniacid = :uniacid and status >= 1 group by openid)\r\n\t\t\t) a group by a.openid HAVING price>=:price ORDER BY price DESC", array( ":uniacid" => $_W["uniacid"], ":price" => $result_one["price"] ));
134
+		$user["paiming"] = count($result_all);
135
+		$seven = $this->orderChange($user["openid"]);
136
+		$user["seven"] = (empty($seven) ? 0 : $seven);
137
+		include($this->template("member/order_rank"));
138
+	}
139
+	public function ajaxorderpage() 
140
+	{
141
+		global $_W;
142
+		global $_GPC;
143
+		$this->orderStatus();
144
+		$pindex = max(1, (int) $_GPC["page"]);
145
+		$psize = 20;
146
+		$num = intval($_W["shopset"]["rank"]["order_num"]);
147
+		if( $num <= 0 ) 
148
+		{
149
+			$num = 50;
150
+		}
151
+		$stop = false;
152
+		if( $num <= $pindex * $psize ) 
153
+		{
154
+			$psize = ($num % $psize == 0 ? 20 : $num % $psize);
155
+			$pindex = ceil($num / $psize);
156
+			$stop = true;
157
+		}
158
+		$limit = " LIMIT " . ($pindex - 1) * $psize . "," . $psize;
159
+		$condition = " and o.uniacid=:uniacid";
160
+		$condition1 = " and m.uniacid=:uniacid";
161
+		$sql = "SELECT m.id,m.uid,m.nickname,m.avatar,m.openid," . "(select ifnull(sum(o.price),0) from  " . tablename("ewei_shop_order") . " o where o.openid=m.openid and o.status>=1 " . $condition . ")  as price" . " from " . tablename("ewei_shop_member") . " m  " . " where 1 " . $condition1 . " order by price desc,createtime desc" . $limit;
162
+		$result = pdo_fetchall($sql, array( ":uniacid" => $_W["uniacid"] ));
163
+		show_json(1, array( "list" => $result, "stop" => $stop ));
164
+	}
165
+	protected function orderChange($openid, $day = 7) 
166
+	{
167
+		global $_W;
168
+		$day = (int) $day;
169
+		if( $day != 0 ) 
170
+		{
171
+			$createtime1 = strtotime(date("Y-m-d", time() - $day * 3600 * 24));
172
+			$createtime2 = strtotime(date("Y-m-d", time()));
173
+		}
174
+		else 
175
+		{
176
+			$createtime1 = strtotime(date("Y-m-d", time()));
177
+			$createtime2 = strtotime(date("Y-m-d", time() + 3600 * 24));
178
+		}
179
+		$sql = "select sum(price) from " . tablename("ewei_shop_order") . " where uniacid = :uniacid and openid = :openid and status >= 1 and createtime between :createtime1 and :createtime2";
180
+		$param = array( ":uniacid" => $_W["uniacid"], ":openid" => $openid, ":createtime1" => $createtime1, ":createtime2" => $createtime2 );
181
+		return pdo_fetchcolumn($sql, $param);
182
+	}
183
+}
184
+function ranksort($a, $b) 
185
+{
186
+	return ($b["credit1"] < $a["credit1"] ? -1 : 1);
187
+}
188
+?>

+ 387 - 0
addons/ewei_shopv2/core/mobile/member/recharge.php Parādīt failu

@@ -0,0 +1,387 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+    exit('Access Denied');
4
+}
5
+
6
+class Recharge_EweiShopV2Page extends MobileLoginPage {
7
+
8
+    function main() {
9
+
10
+        global $_W, $_GPC;
11
+
12
+        //参数
13
+        $set = $_W['shopset'];
14
+        $set['pay']['weixin'] = !empty($set['pay']['weixin_sub']) ? 1 : $set['pay']['weixin'];
15
+        $set['pay']['weixin_jie'] = !empty($set['pay']['weixin_jie_sub']) ? 1 : $set['pay']['weixin_jie'];
16
+
17
+        $sec = m('common')->getSec();
18
+        $sec =iunserializer($sec['sec']);
19
+
20
+        $status = 1;
21
+        if (!empty($set['trade']['closerecharge'])) {
22
+            $this->message('系统未开启充值!', '', 'error');
23
+        }
24
+
25
+        if (empty($set['trade']['minimumcharge'])) {
26
+            $minimumcharge = 0;
27
+        } else {
28
+            $minimumcharge = $set['trade']['minimumcharge'];
29
+        }
30
+
31
+        //当前余额
32
+        $credit = m('member')->getCredit($_W['openid'], 'credit2');
33
+
34
+        //微信支付
35
+        $wechat = array('success' => false);
36
+        if (is_weixin()) {
37
+            //微信环境
38
+            $data = m('common')->getSysset('pay');
39
+            if (isset($set['pay']) && $set['pay']['weixin'] == 1 && !empty($data['weixin_id'])) {
40
+                list(,$payment) = m('common')->public_build();
41
+                if ($payment['is_new']){
42
+                    if ($payment['type'] == 2 || $payment['type'] == 3){
43
+                        if (!empty($payment['sub_appsecret'])){
44
+                            m('member')->wxuser($payment['sub_appid'],$payment['sub_appsecret']);
45
+                        }
46
+                    }
47
+                }
48
+                if (is_array($payment) && !is_error($payment)) {
49
+                    $wechat['success'] = true;
50
+                }elseif ($set['pay']['weixin']){
51
+                    $wechat['success'] = true;
52
+                }
53
+            }
54
+
55
+            if (isset($set['pay']) && $set['pay']['weixin_jie'] == 1 && !$wechat['success']) {
56
+                if (!empty($set['pay']['weixin_jie_sub']) && !empty($sec['sub_secret_jie_sub'])){
57
+                    m('member')->wxuser($sec['sub_appid_jie_sub'],$sec['sub_secret_jie_sub']);
58
+                }elseif(!empty($sec['secret'])){
59
+                    m('member')->wxuser($sec['appid'],$sec['secret']);
60
+                }
61
+                $wechat['success'] = true;
62
+            }
63
+        }
64
+
65
+        //支付宝
66
+        $alipay = array('success' => false);
67
+        if (isset($set['pay']['alipay']) && $set['pay']['alipay'] == 1) {
68
+            //如果开启支付宝
69
+            load()->model('payment');
70
+            $setting = uni_setting($_W['uniacid'], array('payment'));
71
+            if (is_array($setting['payment']['alipay']) && ($setting['payment']['alipay']['switch'] || $setting['payment']['alipay']['recharge_switch'])) {
72
+                $alipay['success'] = true;
73
+            }
74
+        }
75
+
76
+        //充值活动
77
+        $acts = com_run('sale::getRechargeActivity');
78
+
79
+
80
+        if(is_h5app()){
81
+            $payinfo = array(
82
+                'wechat' => !empty($sec['app_wechat']['merchname']) && !empty($set['pay']['app_wechat']) && !empty($sec['app_wechat']['appid']) && !empty($sec['app_wechat']['appsecret']) && !empty($sec['app_wechat']['merchid']) && !empty($sec['app_wechat']['apikey']) ? true : false,
83
+                'alipay' => false,
84
+                'mcname' => $sec['app_wechat']['merchname'],
85
+                'aliname' => empty($_W['shopset']['shop']['name']) ? $sec['app_wechat']['merchname'] : $_W['shopset']['shop']['name'],
86
+                'logno' => null,
87
+                'money' => null,
88
+                'attach' => $_W['uniacid'] . ":1",
89
+                'type' => 1
90
+            );
91
+
92
+            if( !empty($set['pay']['app_alipay']) && ( !empty($sec['app_alipay']['public_key'])|| !empty($sec['app_alipay']['public_key_rsa2']) ) ){
93
+                $payinfo['alipay']=true;
94
+            }
95
+        }
96
+
97
+        include $this->template();
98
+    }
99
+
100
+    function submit() {
101
+        global $_W, $_GPC;
102
+        $set = $_W['shopset'];
103
+
104
+        if (empty($set['trade']['minimumcharge'])||$set['trade']['minimumcharge']<=0) {
105
+            $minimumcharge = 1;
106
+        } else {
107
+            $minimumcharge = $set['trade']['minimumcharge'];
108
+        }
109
+
110
+        $money = floatval($_GPC['money']);
111
+        if ($money <= 0) {
112
+            show_json(0, '充值金额必须大于0!');
113
+        }
114
+        if ($money < $minimumcharge && $minimumcharge > 0) {
115
+            show_json(0, '最低充值金额为' .$minimumcharge . '元!');
116
+        }
117
+        if (empty($money)) {
118
+            show_json(0, '请填写充值金额!');
119
+        }
120
+
121
+        pdo_delete('ewei_shop_member_log', array('openid' => $_W['openid'], 'status' => 0, 'type' => 0, 'uniacid' => $_W['uniacid']));
122
+        $logno = m('common')->createNO('member_log', 'logno', 'RC');
123
+        //日志
124
+        $log = array(
125
+            'uniacid' => $_W['uniacid'],
126
+            'logno' => $logno,
127
+            'title' => $set['shop']['name'] . "会员充值",
128
+            'openid' => $_W['openid'],
129
+            'money'=>$money,
130
+            'type' => 0,
131
+            'createtime' => time(),
132
+            'status' => 0,
133
+            'couponid' => intval($_GPC['couponid'])
134
+        );
135
+        pdo_insert('ewei_shop_member_log', $log);
136
+        $logid = pdo_insertid();
137
+        $type = $_GPC['type'];
138
+
139
+        if (empty($logid) || (int)$logid<1) {
140
+            show_json(0, '充值订单创建失败请重试!');
141
+        }
142
+        if(is_h5app()){
143
+            show_json(1, array(
144
+                'logno'=>$logno,
145
+                'money'=>$money
146
+            ));
147
+        }
148
+
149
+        //参数
150
+        $set = m('common')->getSysset(array('shop', 'pay'));
151
+        $set['pay']['weixin'] = !empty($set['pay']['weixin_sub']) ? 1 : $set['pay']['weixin'];
152
+        $set['pay']['weixin_jie'] = !empty($set['pay']['weixin_jie_sub']) ? 1 : $set['pay']['weixin_jie'];
153
+        if ($type == 'wechat') {
154
+            //微信支付
155
+            if (!is_weixin()) {
156
+                show_json(0, '非微信环境!');
157
+            }
158
+            //微信环境
159
+            if (empty($set['pay']['weixin'])&&empty($set['pay']['weixin_jie'])) {
160
+                show_json(0, '未开启微信支付!');
161
+            }
162
+            $wechat = array('success' => false);
163
+            $jie = intval($_GPC['jie']);
164
+            //如果开启微信支付
165
+            $params = array();
166
+            $params['tid'] = $log['logno'];
167
+            $params['user'] = $_W['openid'];
168
+            $params['fee'] = $money;
169
+            $params['title'] = $log['title'];
170
+
171
+            if (isset($set['pay']) && $set['pay']['weixin'] == 1&&$jie!==1) {
172
+                load()->model('payment');
173
+                $setting = uni_setting($_W['uniacid'], array('payment'));
174
+                $options = array();
175
+                if (is_array($setting['payment'])) {
176
+                    $options = $setting['payment']['wechat'];
177
+                    $options['appid'] = $_W['account']['key'];
178
+                    $options['secret'] = $_W['account']['secret'];
179
+                }
180
+                $wechat = m('common')->wechat_build($params, $options, 1);
181
+                if (!is_error($wechat)) {
182
+                    $wechat['success'] = true;
183
+                    if (!empty($wechat['code_url'])){
184
+                        $wechat['weixin_jie'] = true;
185
+                    }else{
186
+                        $wechat['weixin'] = true;
187
+                    }
188
+                }
189
+            }
190
+            if ((isset($set['pay']) && $set['pay']['weixin_jie'] == 1&& !$wechat['success'])||$jie===1) {
191
+                $params['tid'] = $params['tid'].'_borrow';
192
+                $sec = m('common')->getSec();
193
+                $sec =iunserializer($sec['sec']);
194
+                $options = array();
195
+                $options['appid'] = $sec['appid'];
196
+                $options['mchid'] = $sec['mchid'];
197
+                $options['apikey'] = $sec['apikey'];
198
+                if (!empty($set['pay']['weixin_jie_sub']) && !empty($sec['sub_secret_jie_sub'])){
199
+                    $wxuser = m('member')->wxuser($sec['sub_appid_jie_sub'],$sec['sub_secret_jie_sub']);
200
+                    $params['openid'] = $wxuser['openid'];
201
+                }elseif(!empty($sec['secret'])){
202
+                    $wxuser = m('member')->wxuser($sec['appid'],$sec['secret']);
203
+                    $params['openid'] = $wxuser['openid'];
204
+                }
205
+
206
+                $wechat = m('common')->wechat_native_build($params, $options, 1);
207
+                if (!is_error($wechat)) {
208
+                    $wechat['success'] = true;
209
+                    if (!empty($params['openid'])){
210
+                        $wechat['weixin'] = true;
211
+                    }else{
212
+                        $wechat['weixin_jie'] = true;
213
+                    }
214
+                }
215
+            }
216
+            $wechat['jie'] = $jie;
217
+            if (!$wechat['success']) {
218
+                show_json(0, '微信支付参数错误!');
219
+            }
220
+            show_json(1, array(
221
+                'wechat' => $wechat,
222
+                'logid' => $logid
223
+            ));
224
+        } else if ($type == 'alipay') {
225
+
226
+            //支付宝
227
+            $alipay = array('success' => false);
228
+            //如果开启支付宝
229
+            $params = array();
230
+            $params['tid'] = $log['logno'];
231
+            $params['user'] = $_W['openid'];
232
+            $params['fee'] = $money;
233
+            $params['title'] = $log['title'];
234
+
235
+            load()->func('communication');
236
+            load()->model('payment');
237
+            $setting = uni_setting($_W['uniacid'], array('payment'));
238
+            if (is_array($setting['payment'])) {
239
+                $options = $setting['payment']['alipay'];
240
+                $alipay = m('common')->alipay_build($params, $options, 1, $_W['openid']);
241
+                if (!empty($alipay['url'])) {
242
+                    $alipay['url'] = urlencode($alipay['url']);
243
+                    $alipay['success'] = true;
244
+                }
245
+            }
246
+            list(,$payment) = m('common')->public_build();
247
+
248
+            if ($payment['type'] == '4'){
249
+                $params = array(
250
+                    'service' => 'pay.alipay.native',
251
+                    'body' => $params['title'],
252
+                    'out_trade_no' => $params['tid'],
253
+                    'total_fee' => $money
254
+                );
255
+
256
+                if (!empty($order['ordersn2'])) {
257
+                    $params['out_trade_no'] = $log['logno'] . '_B';
258
+                } else {
259
+                    $params['out_trade_no'] = $log['logno'] . '_borrow';
260
+                }
261
+
262
+                $AliPay = m('pay')->build($params, $payment,1);
263
+                if (!empty($AliPay) && !is_error($AliPay)){
264
+                    $alipay['url'] = urlencode($AliPay['code_url']);
265
+                    $alipay['success'] = true;
266
+                }
267
+            }
268
+
269
+            show_json(1, array('alipay' => $alipay,'logid' => $logid, 'logno'=>$logno));
270
+        }
271
+        show_json(0, '未找到支付方式');
272
+    }
273
+
274
+    function wechat_complete() {
275
+        global $_W, $_GPC;
276
+
277
+        $logid = intval($_GPC['logid']);
278
+        $log = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_member_log') . ' WHERE `id`=:id and `uniacid`=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':id' => $logid));
279
+        if(empty($log)){
280
+            $logno = intval($_GPC['logno']);
281
+            $log = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_member_log') . ' WHERE `logno`=:logno and `uniacid`=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':logno' => $logno));
282
+        }
283
+
284
+        if (!empty($log)) {
285
+            if (empty($log['status']))
286
+            {
287
+                show_json(0);
288
+            }
289
+            else
290
+            {
291
+                if($_W['ispost']){
292
+                    show_json(1);
293
+                }else{
294
+                    header('location: ' . mobileUrl('member'));
295
+                }
296
+            }
297
+        }
298
+        if($_W['ispost']){
299
+            show_json(0);
300
+        }else{
301
+            header('location: ' . mobileUrl('member'));
302
+        }
303
+    }
304
+/*
305
+    function alipay_complete() {
306
+        global $_W, $_GPC;
307
+        $logno = trim($_GPC['out_trade_no']);
308
+        $notify_id = trim($_GPC['notify_id']); //支付宝通知ID
309
+        $sign = trim($_GPC['sign']);
310
+
311
+
312
+        if(is_h5app()){
313
+            $set = m('common')->getSysset(array('shop', 'pay'));
314
+            $sec = m('common')->getSec();
315
+            $sec =iunserializer($sec['sec']);
316
+            $public_key = $sec['app_alipay']['public_key'];
317
+
318
+            if(empty($_GET['alidata'])){
319
+                $this->message('支付出现错误,请重试(1)!', mobileUrl('member'));
320
+            }
321
+
322
+            if(empty($set['pay']['app_alipay']) || empty($public_key)){
323
+                $this->message('支付出现错误,请重试(2)!', mobileUrl('order'));
324
+            }
325
+
326
+            $alidata = base64_decode($_GET['alidata']);
327
+
328
+            $alidata = json_decode($alidata, true);
329
+            $alisign = m('finance')->RSAVerify($alidata, $public_key, false);
330
+
331
+            $logno = $this->str($alidata['out_trade_no']);
332
+
333
+            if($alisign==0){
334
+                $this->message('支付出现错误,请重试(3)!', mobileUrl('member'));
335
+            }
336
+
337
+        }else{
338
+
339
+            if (empty($logno)) {
340
+                die('[ERR1]充值出现错误,请重试!');
341
+            }
342
+
343
+            if(empty($set['pay']['alipay']) && is_weixin()){
344
+                $this->message('未开启支付宝支付!', mobileUrl('order'));
345
+            }
346
+
347
+            if (!m('finance')->isAlipayNotify($_GET)) {
348
+                die('[ERR2]充值出现错误,请重试!');
349
+            }
350
+
351
+        }
352
+
353
+        $log = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_member_log') . ' WHERE `logno`=:logno and `uniacid`=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':logno' => $logno));
354
+        if (!empty($log) && empty($log['status'])) {
355
+
356
+            //充值状态
357
+            pdo_update('ewei_shop_member_log', array('status' => 1, 'rechargetype' => 'alipay', 'apppay'=>is_h5app()?1:0), array('id' => $log['id']));
358
+            //增加会员余额
359
+            m('member')->setCredit($log['openid'], 'credit2', $log['money'], array(0, $_W['shopset']['shop']['name'].'会员充值:alipayreturn:credit2:' . $log['money']));
360
+            //充值积分
361
+            m('member')->setRechargeCredit($log['openid'], $log['money']);
362
+            //充值活动
363
+            com_run('sale::setRechargeActivity', $log);
364
+
365
+            //优惠券
366
+            com_run('coupon::useRechargeCoupon', $log);
367
+
368
+            //模板消息
369
+            m('notice')->sendMemberLogMessage($log['id']);
370
+        }
371
+        $url = mobileUrl('member', null, true);
372
+        die("<script>top.window.location.href='{$url}'</script>");
373
+    }*/
374
+
375
+    public function getstatus(){
376
+        global $_W, $_GPC;
377
+        $logno = $_GPC['logno'];
378
+        $log = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_member_log') . ' WHERE `logno`=:logno and `uniacid`=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':logno' => $logno));
379
+
380
+        if (!empty($log) && !empty($log['status'])) {
381
+            show_json(1);
382
+        }else{
383
+            show_json(0);
384
+        }
385
+    }
386
+
387
+}

+ 244 - 0
addons/ewei_shopv2/core/mobile/member/withdraw.php Parādīt failu

@@ -0,0 +1,244 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+    exit('Access Denied');
4
+}
5
+
6
+class Withdraw_EweiShopV2Page extends MobileLoginPage {
7
+
8
+    function main() {
9
+
10
+        global $_W, $_GPC;
11
+        //参数
12
+        $set = $_W['shopset']['trade'];
13
+        $status = 1;
14
+
15
+        $openid = $_W['openid'];
16
+
17
+        if (empty($set['withdraw'])) {
18
+            $this->message('系统未开启提现!', '', 'error');
19
+
20
+        }
21
+
22
+        $withdrawcharge = $set['withdrawcharge'];
23
+        $withdrawbegin = floatval($set['withdrawbegin']);
24
+        $withdrawend = floatval($set['withdrawend']);
25
+        $withdrawmoney = 0;
26
+        if(floatval($set['withdrawmoney']) > 0) $withdrawmoney = floatval($set['withdrawmoney']);
27
+
28
+        //当前余额
29
+        $credit = m('member')->getCredit($_W['openid'], 'credit2');
30
+
31
+        $last_data = $this->getLastApply($openid);
32
+
33
+        // 判断openid是否是微信公众号的
34
+        $canusewechat = !strexists($openid, 'wap_user_') && !strexists($openid, 'sns_qq_') && !strexists($openid, 'sns_wx_') && !strexists($openid, 'sns_wa_');
35
+
36
+        //提现方式
37
+        $type_array = array();
38
+
39
+        if($set['withdrawcashweixin'] == 1 && $canusewechat) {
40
+            $type_array[0]['title'] = '提现到微信钱包';
41
+        }
42
+
43
+        if($set['withdrawcashalipay'] == 1) {
44
+            $type_array[2]['title'] = '提现到支付宝';
45
+
46
+            if (!empty($last_data)) {
47
+                if ($last_data['applytype'] != 2) {
48
+                    $type_last = $this->getLastApply($openid, 2);
49
+
50
+                    if (!empty($type_last)) {
51
+                        $last_data['alipay'] = $type_last['alipay'];
52
+                    }
53
+                }
54
+            }
55
+        }
56
+
57
+        if($set['withdrawcashcard'] == 1) {
58
+            $type_array[3]['title'] = '提现到银行卡';
59
+
60
+            if (!empty($last_data)) {
61
+                if ($last_data['applytype'] != 3) {
62
+                    $type_last = $this->getLastApply($openid, 3);
63
+                    if (!empty($type_last)) {
64
+                        $last_data['bankname'] = $type_last['bankname'];
65
+                        $last_data['bankcard'] = $type_last['bankcard'];
66
+                    }
67
+                }
68
+            }
69
+
70
+            $condition = " and uniacid=:uniacid";
71
+            $params = array(':uniacid' => $_W['uniacid']);
72
+            $banklist = pdo_fetchall("SELECT * FROM " . tablename('ewei_shop_commission_bank') . " WHERE 1 {$condition}  ORDER BY displayorder DESC", $params);
73
+        }
74
+
75
+        if (!empty($last_data)) {
76
+            if (array_key_exists($last_data['applytype'], $type_array)) {
77
+                $type_array[$last_data['applytype']]['checked'] = 1;
78
+            }
79
+        }
80
+
81
+        include $this->template();
82
+    }
83
+
84
+    function submit() {
85
+        global $_W, $_GPC;
86
+
87
+        $set = $_W['shopset']['trade'];
88
+        if (empty($set['withdraw'])) {
89
+            show_json(0,'系统未开启提现!');
90
+        }
91
+
92
+        $set_array = array();
93
+        $set_array['charge'] = $set['withdrawcharge'];
94
+        $set_array['begin'] = floatval($set['withdrawbegin']);
95
+        $set_array['end'] = floatval($set['withdrawend']);
96
+
97
+        $money = floatval($_GPC['money']);
98
+        $credit = m('member')->getCredit($_W['openid'], 'credit2');
99
+
100
+        if($money <= 0){
101
+            show_json(0,'提现金额错误!');
102
+        }
103
+
104
+        if ($money > $credit) {
105
+            show_json(0, '提现金额过大!');
106
+        }
107
+
108
+        //高并发下单支付库款多次的问题
109
+        $open_redis = function_exists('redis') && !is_error(redis());
110
+        if( $open_redis ) {
111
+            $redis_key = "{$_W['uniacid']}_member_withdraw__pay_{$_W['openid']}";
112
+            $redis = redis();
113
+            if (!is_error($redis)) {
114
+                if($redis->get($redis_key)) {
115
+                    show_json(0,'请勿重复点击');
116
+                }
117
+                $redis->setex($redis_key, 1,time());
118
+            }
119
+        }
120
+
121
+        //生成申请
122
+        $apply = array();
123
+
124
+        //提现方式
125
+        $type_array = array();
126
+
127
+        if($set['withdrawcashweixin'] == 1) {
128
+            $type_array[0]['title'] = '提现到微信钱包';
129
+        }
130
+
131
+        if($set['withdrawcashalipay'] == 1) {
132
+            $type_array[2]['title'] = '提现到支付宝';
133
+        }
134
+
135
+        if($set['withdrawcashcard'] == 1) {
136
+            $type_array[3]['title'] = '提现到银行卡';
137
+            $condition = " and uniacid=:uniacid";
138
+            $params = array(':uniacid' => $_W['uniacid']);
139
+            $banklist = pdo_fetchall("SELECT * FROM " . tablename('ewei_shop_commission_bank') . " WHERE 1 {$condition}  ORDER BY displayorder DESC", $params);
140
+        }
141
+
142
+        $applytype = intval($_GPC['applytype']);
143
+        if (!array_key_exists($applytype, $type_array)) {
144
+            show_json(0, '未选择提现方式,请您选择提现方式后重试!');
145
+        }
146
+
147
+        if ($applytype == 2) {
148
+            //支付宝
149
+            $realname = trim($_GPC['realname']);
150
+            $alipay = trim($_GPC['alipay']);
151
+            $alipay1 = trim($_GPC['alipay1']);
152
+            if (empty($realname)) {
153
+                show_json(0, '请填写姓名!');
154
+            }
155
+            if (empty($alipay)) {
156
+                show_json(0, '请填写支付宝帐号!');
157
+            }
158
+            if (empty($alipay1)) {
159
+                show_json(0, '请填写确认帐号!');
160
+            }
161
+            if ($alipay != $alipay1) {
162
+                show_json(0, '支付宝帐号与确认帐号不一致!');
163
+            }
164
+            $apply['realname'] = $realname;
165
+            $apply['alipay'] = $alipay;
166
+        } else if ($applytype == 3) {
167
+            //银行卡号
168
+            $realname = trim($_GPC['realname']);
169
+            $bankname = trim($_GPC['bankname']);
170
+            $bankcard = trim($_GPC['bankcard']);
171
+            $bankcard1 = trim($_GPC['bankcard1']);
172
+            if (empty($realname)) {
173
+                show_json(0, '请填写姓名!');
174
+            }
175
+            if (empty($bankname)) {
176
+                show_json(0, '请选择银行!');
177
+            }
178
+            if (empty($bankcard)) {
179
+                show_json(0, '请填写银行卡号!');
180
+            }
181
+            if (empty($bankcard1)) {
182
+                show_json(0, '请填写确认卡号!');
183
+            }
184
+            if ($bankcard != $bankcard1) {
185
+                show_json(0, '银行卡号与确认卡号不一致!');
186
+            }
187
+            $apply['realname'] = $realname;
188
+            $apply['bankname'] = $bankname;
189
+            $apply['bankcard'] = $bankcard;
190
+        }
191
+
192
+        $realmoney = $money;
193
+        if (!empty($set_array['charge'])) {
194
+            $money_array = m('member')->getCalculateMoney($money, $set_array);
195
+
196
+            if($money_array['flag']) {
197
+                $realmoney = $money_array['realmoney'];
198
+                $deductionmoney = $money_array['deductionmoney'];
199
+            }
200
+        }
201
+
202
+        m('member')->setCredit($_W['openid'], 'credit2', -$money, array(0,$_W['shopset']['set'][''].'余额提现预扣除: ' . $money . ',实际到账金额:' . $realmoney . ',手续费金额:' . $deductionmoney ));
203
+        $logno = m('common')->createNO('member_log', 'logno', 'RW');
204
+
205
+        $apply['uniacid'] = $_W['uniacid'];
206
+        $apply['logno'] = $logno;
207
+        $apply['openid'] = $_W['openid'];
208
+        $apply['title'] = '余额提现';
209
+        $apply['type'] = 1;
210
+        $apply['createtime'] = time();
211
+        $apply['status'] = 0;
212
+        $apply['money'] = $money;
213
+        $apply['realmoney'] = $realmoney;
214
+        $apply['deductionmoney'] = $deductionmoney;
215
+        $apply['charge'] = $set_array['charge'];
216
+        $apply['applytype'] = $applytype;
217
+
218
+        pdo_insert('ewei_shop_member_log', $apply);
219
+        $logid = pdo_insertid();
220
+
221
+        //模板消息
222
+        m('notice')->sendMemberLogMessage($logid);
223
+
224
+        show_json(1);
225
+    }
226
+
227
+    function getLastApply($openid, $applytype = -1)
228
+    {
229
+        global $_W;
230
+
231
+        $params = array(':uniacid' => $_W['uniacid'],':openid'=>$openid);
232
+        $sql = "select applytype,alipay,bankname,bankcard,realname from " . tablename('ewei_shop_member_log') . " where openid=:openid and uniacid=:uniacid";
233
+
234
+        if ($applytype > -1) {
235
+            $sql .= " and applytype=:applytype";
236
+            $params[':applytype'] = $applytype;
237
+        }
238
+        $sql .= " order by id desc Limit 1";
239
+        $data = pdo_fetch($sql, $params);
240
+
241
+        return $data;
242
+    }
243
+
244
+}

+ 107 - 0
addons/ewei_shopv2/core/mobile/order/comment.php Parādīt failu

@@ -0,0 +1,107 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Comment_EweiShopV2Page extends MobileLoginPage
7
+{
8
+	public function __construct()
9
+	{
10
+		parent::__construct();
11
+		$trade = m('common')->getSysset('trade');
12
+
13
+		if (!empty($trade['closecomment'])) {
14
+			$this->message('不允许评论!', '', 'error');
15
+		}
16
+	}
17
+
18
+	public function main()
19
+	{
20
+		global $_W;
21
+		global $_GPC;
22
+		$uniacid = $_W['uniacid'];
23
+		$openid = $_W['openid'];
24
+		$orderid = intval($_GPC['id']);
25
+		$order = pdo_fetch('select id,status,iscomment from ' . tablename('ewei_shop_order') . ' where id=:id and uniacid=:uniacid and openid=:openid limit 1', array(':id' => $orderid, ':uniacid' => $uniacid, ':openid' => $openid));
26
+
27
+		if (empty($order)) {
28
+			header('location: ' . mobileUrl('order'));
29
+			exit();
30
+		}
31
+
32
+		if ($order['status'] != 3 && $order['status'] != 4) {
33
+			$this->message('订单未收货,不能评价!', mobileUrl('order/detail', array('id' => $orderid)));
34
+		}
35
+
36
+		if (2 <= $order['iscomment']) {
37
+			$this->message('您已经评价过了!', mobileUrl('order/detail', array('id' => $orderid)));
38
+		}
39
+
40
+		$goods = pdo_fetchall('select og.id,og.goodsid,og.price,g.title,g.thumb,og.total,g.credit,og.optionid,o.title as optiontitle from ' . tablename('ewei_shop_order_goods') . ' og ' . ' left join ' . tablename('ewei_shop_goods') . ' g on g.id=og.goodsid ' . ' left join ' . tablename('ewei_shop_goods_option') . ' o on o.id=og.optionid ' . ' where og.orderid=:orderid and og.uniacid=:uniacid ', array(':uniacid' => $uniacid, ':orderid' => $orderid));
41
+		$goods = set_medias($goods, 'thumb');
42
+		include $this->template();
43
+	}
44
+
45
+	public function submit()
46
+	{
47
+		global $_W;
48
+		global $_GPC;
49
+		$openid = $_W['openid'];
50
+		$uniacid = $_W['uniacid'];
51
+		$orderid = intval($_GPC['orderid']);
52
+		$order = pdo_fetch('select id,status,iscomment from ' . tablename('ewei_shop_order') . ' where id=:id and uniacid=:uniacid and openid=:openid limit 1', array(':id' => $orderid, ':uniacid' => $uniacid, ':openid' => $openid));
53
+
54
+		if (empty($order)) {
55
+			show_json(0, '订单未找到');
56
+		}
57
+
58
+		$member = m('member')->getMember($openid);
59
+		$comments = $_GPC['comments'];
60
+
61
+		if (!is_array($comments)) {
62
+			show_json(0, '数据出错,请重试!');
63
+		}
64
+
65
+		$trade = m('common')->getSysset('trade');
66
+
67
+		if (!empty($trade['commentchecked'])) {
68
+			$checked = 0;
69
+		}
70
+		else {
71
+			$checked = 1;
72
+		}
73
+
74
+		foreach ($comments as $c) {
75
+			$old_c = pdo_fetchcolumn('select count(*) from ' . tablename('ewei_shop_order_comment') . ' where uniacid=:uniacid and orderid=:orderid and goodsid=:goodsid limit 1', array(':uniacid' => $_W['uniacid'], ':goodsid' => $c['goodsid'], ':orderid' => $orderid));
76
+
77
+			if (empty($old_c)) {
78
+				$comment = array('uniacid' => $uniacid, 'orderid' => $orderid, 'goodsid' => $c['goodsid'], 'level' => $c['level'], 'content' => trim($c['content']), 'images' => is_array($c['images']) ? iserializer($c['images']) : iserializer(array()), 'openid' => $openid, 'nickname' => $member['nickname'], 'headimgurl' => $member['avatar'], 'createtime' => time(), 'checked' => $checked);
79
+				pdo_insert('ewei_shop_order_comment', $comment);
80
+
81
+				if (p('task')) {
82
+					p('task')->checkTaskReward('cost_comment', 1);
83
+				}
84
+
85
+				if (p('task')) {
86
+					p('task')->checkTaskProgress(1, 'comment');
87
+				}
88
+			}
89
+			else {
90
+				$comment = array('append_content' => trim($c['content']), 'append_images' => is_array($c['images']) ? iserializer($c['images']) : iserializer(array()), 'replychecked' => $checked);
91
+				pdo_update('ewei_shop_order_comment', $comment, array('uniacid' => $_W['uniacid'], 'goodsid' => $c['goodsid'], 'orderid' => $orderid));
92
+			}
93
+		}
94
+
95
+		if ($order['iscomment'] <= 0) {
96
+			$d['iscomment'] = 1;
97
+		}
98
+		else {
99
+			$d['iscomment'] = 2;
100
+		}
101
+
102
+		pdo_update('ewei_shop_order', $d, array('id' => $orderid, 'uniacid' => $uniacid));
103
+		show_json(1);
104
+	}
105
+}
106
+
107
+?>

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 5130 - 0
addons/ewei_shopv2/core/mobile/order/create.php


+ 902 - 0
addons/ewei_shopv2/core/mobile/order/index.php Parādīt failu

@@ -0,0 +1,902 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+    exit('Access Denied');
4
+}
5
+
6
+class Index_EweiShopV2Page extends MobileLoginPage {
7
+
8
+    //多商户
9
+    protected function merchData() {
10
+        $merch_plugin = p('merch');
11
+        $merch_data = m('common')->getPluginset('merch');
12
+        if ($merch_plugin && $merch_data['is_openmerch']) {
13
+            $is_openmerch = 1;
14
+        } else {
15
+            $is_openmerch = 0;
16
+        }
17
+
18
+        return array(
19
+            'is_openmerch' => $is_openmerch,
20
+            'merch_plugin' => $merch_plugin,
21
+            'merch_data' => $merch_data
22
+        );
23
+    }
24
+
25
+    function main() {
26
+        global $_W,$_GPC;
27
+        $trade = m('common')->getSysset('trade');
28
+
29
+        //多商户
30
+        $merchdata = $this->merchData();
31
+        extract($merchdata);
32
+
33
+        if ($is_openmerch == 1) {
34
+            include $this->template('merch/order/index');
35
+        }else{
36
+            include $this->template();
37
+        }
38
+    }
39
+
40
+    function get_list(){
41
+
42
+        global $_W,$_GPC;
43
+        $uniacid =$_W['uniacid'];
44
+        $openid =$_W['openid'];
45
+        $pindex = max(1, intval($_GPC['page']));
46
+        $psize = 50;
47
+        $show_status = $_GPC['status'];
48
+        $r_type = array( '0' => '退款', '1' => '退货退款', '2' => '换货');
49
+        $condition = " and openid=:openid and ismr=0 and deleted=0 and uniacid=:uniacid and istrade=0 ";
50
+        $params = array(
51
+            ':uniacid' => $uniacid,
52
+            ':openid' => $openid
53
+        );
54
+
55
+        //多商户
56
+        $merchdata = $this->merchData();
57
+        extract($merchdata);
58
+
59
+        $condition .= " and merchshow=0 ";
60
+
61
+        if ($show_status != '') {
62
+            $show_status =intval($show_status);
63
+
64
+            switch ($show_status)
65
+            {
66
+                case 0:
67
+                    $condition.=' and status=0 and paytype<>3';
68
+                    break;
69
+                case 1:
70
+                    $condition.=' and (status=1 or (status=0 and paytype=3))';
71
+                    break;
72
+                case 2:
73
+                    $condition.=' and (status=2 or (status=1 and sendtype>0))';
74
+                    break;
75
+                case 4:
76
+                    $condition.=' and refundstate>0';
77
+                    break;
78
+                case 5:
79
+                    $condition .= " and userdeleted=1 ";
80
+                    break;
81
+                default:
82
+                    $condition.=' and status=' . intval($show_status);
83
+            }
84
+
85
+            if ($show_status != 5) {
86
+                $condition .= " and userdeleted=0 ";
87
+            }
88
+        } else {
89
+            $condition .= " and userdeleted=0 ";
90
+        }
91
+
92
+        $com_verify = com('verify');
93
+
94
+        $s_string = '';
95
+
96
+        $list = pdo_fetchall("select id,addressid,ordersn,price,dispatchprice,status,iscomment,isverify,verifyendtime,
97
+verified,verifycode,verifytype,iscomment,refundid,expresscom,express,expresssn,finishtime,`virtual`,sendtype,
98
+paytype,expresssn,refundstate,dispatchtype,verifyinfo,merchid,isparent,iscycelbuy,cycelbuy_periodic,userdeleted{$s_string}
99
+ from " . tablename('ewei_shop_order') . " where 1 {$condition} order by createtime desc LIMIT " . ($pindex - 1) * $psize . ',' . $psize, $params);
100
+        $total = pdo_fetchcolumn('select count(*) from ' . tablename('ewei_shop_order') . " where 1 {$condition}", $params);
101
+
102
+        $refunddays = intval($_W['shopset']['trade']['refunddays']);
103
+        if ($is_openmerch == 1) {
104
+            $merch_user = $merch_plugin->getListUser($list,'merch_user');
105
+        }
106
+
107
+        foreach ($list as &$row) {
108
+
109
+            $param = array();
110
+
111
+            if ($row['isparent'] == 1) {
112
+                $scondition = " og.parentorderid=:parentorderid";
113
+                $param[':parentorderid'] = $row['id'];
114
+            } else {
115
+                $scondition = " og.orderid=:orderid";
116
+                $param[':orderid'] = $row['id'];
117
+            }
118
+
119
+            //所有商品
120
+            $sql = "SELECT og.id,og.goodsid,og.total,g.title,g.thumb,g.type,g.status,og.price,og.title as gtitle,og.optionname as optiontitle,og.optionid,op.specs,g.merchid,og.seckill,og.seckill_taskid,
121
+                og.sendtype,og.expresscom,og.expresssn,og.express,og.sendtime,og.finishtime,og.remarksend,og.single_refundid,og.single_refundstate
122
+                FROM " . tablename('ewei_shop_order_goods') . " og "
123
+                . " left join " . tablename('ewei_shop_goods') . " g on og.goodsid = g.id "
124
+                . " left join " . tablename('ewei_shop_goods_option') . " op on og.optionid = op.id "
125
+                . " where $scondition order by og.id asc";
126
+
127
+            $goods = pdo_fetchall($sql, $param);
128
+
129
+            $ismerch = 0;
130
+            $merch_array = array();
131
+
132
+            $row['isonlyverifygoods'] = false;
133
+            foreach($goods as &$r){
134
+                $r['seckilltask'] = false;
135
+                if($r['seckill']){
136
+                    $r['seckill_task'] = plugin_run('seckill::getTaskInfo',$r['seckill_taskid']);
137
+                }
138
+                $merchid = (int)$r['merchid'];
139
+                $merch_array[$merchid]= $merchid;
140
+                //读取规格的图片
141
+                if (!empty($r['specs'])) {
142
+                    $thumb = m('goods')->getSpecThumb($r['specs']);
143
+                    if (!empty($thumb)) {
144
+                        $r['thumb'] = $thumb;
145
+                    }
146
+                }
147
+                if($r['type']==5){
148
+                    $row['isonlyverifygoods'] = true;
149
+                }
150
+                if(empty($r['gtitle'])!=true){
151
+                    $r['title']=$r['gtitle'];
152
+                }
153
+            }
154
+            unset($r);
155
+
156
+            if (!empty($merch_array)) {
157
+                if (count($merch_array) > 1) {
158
+                    $ismerch = 1;
159
+                }
160
+            }
161
+            $goods = set_medias($goods, 'thumb');
162
+
163
+            if(empty($goods)){
164
+                $goods = array();
165
+            }
166
+            foreach($goods as &$r){
167
+                $r['thumb'].="?t=".random(50);
168
+            }
169
+            unset($r);
170
+
171
+            $goods_list = array();
172
+            if ($ismerch) {
173
+                $getListUser = $merch_plugin->getListUser($goods);
174
+                $merch_user = $getListUser['merch_user'];
175
+
176
+                foreach ($getListUser['merch'] as $k => $v) {
177
+                    if (empty($merch_user[$k]['merchname'])) {
178
+                        $goods_list[$k]['shopname'] = $_W['shopset']['shop']['name'];
179
+                    }else{
180
+                        $goods_list[$k]['shopname'] = $merch_user[$k]['merchname'];
181
+                    }
182
+                    $goods_list[$k]['goods'] = $v;
183
+                }
184
+            } else {
185
+                if ($merchid == 0) {
186
+                    $goods_list[0]['shopname'] = $_W['shopset']['shop']['name'];
187
+                } else {
188
+                    $merch_data = $merch_plugin->getListUserOne($merchid);
189
+                    $goods_list[0]['shopname'] = $merch_data['merchname'];
190
+                }
191
+                $goods_list[0]['goods'] = $goods;
192
+            }
193
+
194
+
195
+            $row['goods'] = $goods_list;
196
+            $row['goods_num'] = count($goods);
197
+            $cycelbuy_periodic = explode( ',' , $row['cycelbuy_periodic'] );
198
+            $row['phaseNum'] =$cycelbuy_periodic['2'];
199
+            $statuscss = "text-cancel";
200
+
201
+            switch ($row['status']) {
202
+                case "-1":
203
+                    $status = "已取消";
204
+                    break;
205
+                case "0":
206
+                    if ($row['paytype'] == 3) {
207
+
208
+                        $status = "待发货";
209
+                    } else {
210
+                        $status = "待付款";
211
+                    }
212
+                    $statuscss = "text-cancel";
213
+                    break;
214
+                case "1":
215
+                    if ($row['isverify'] == 1) {
216
+                        $status = "使用中";
217
+                        //lynn核销时间限制判断
218
+                        if($row['verifyendtime'] > 0 && $row['verifyendtime'] < time() ){
219
+                            $row['status'] = -1;
220
+                            $status = "已过期";
221
+                        }
222
+                    } else if (empty($row['addressid'])) {
223
+                        if (!empty($row['ccard'])) {
224
+                            $status = "充值中";
225
+                        } else {
226
+                            $status = "待取货";
227
+                        }
228
+                    } else {
229
+                        $status = "待发货";
230
+                        if($row['sendtype']>0){
231
+                            $status = "部分发货";
232
+                        }
233
+                    }
234
+                    $statuscss = "text-warning";
235
+                    break;
236
+                case "2":
237
+                    $status = "待收货";
238
+                    $statuscss = "text-danger";
239
+                    break;
240
+                case "3":
241
+                    if (empty($row['iscomment'])) {
242
+                        if ($show_status == 5) {
243
+                            $status = "已完成";
244
+                        } else {
245
+                            $status = empty($_W['shopset']['trade']['closecomment']) ? "待评价" : "已完成";
246
+
247
+                        }
248
+                    } else {
249
+                        $status = "交易完成";
250
+                    }
251
+                    $statuscss = "text-success";
252
+                    break;
253
+            }
254
+            $row['statusstr'] = $status;
255
+            $row['statuscss'] = $statuscss;
256
+            if ($row['refundstate'] > 0 && !empty($row['refundid'])) {
257
+
258
+                $refund = pdo_fetch("select * from " . tablename('ewei_shop_order_refund') . ' where id=:id and uniacid=:uniacid and orderid=:orderid limit 1'
259
+                    , array(':id' => $row['refundid'], ':uniacid' => $uniacid, ':orderid' => $row['id']));
260
+
261
+                if (!empty($refund)) {
262
+                    $row['statusstr'] = '待' . $r_type[$refund['rtype']];
263
+                }
264
+            }
265
+            //是否可以退款
266
+            $canrefund = false;
267
+            /*if ($row['status'] == 1 || $row['status'] == 2) {
268
+                $canrefund = true;
269
+                if ($row['status'] == 2 && $row['price'] == $row['dispatchprice']) {
270
+                    if ($row['refundstate'] > 0) {
271
+                        $canrefund = true;
272
+                    } else {
273
+                        $canrefund = false;
274
+                    }
275
+                }
276
+            } else if ($row['status'] == 3) {
277
+                if ($row['isverify'] != 1 && empty($row['virtual'])) { //如果不是核销或虚拟物品,则可以退货
278
+                    if ($row['refundstate'] > 0) {
279
+                        $canrefund = true;
280
+                    } else {
281
+                        if ($refunddays > 0) {
282
+                            $days = intval((time() - $row['finishtime']) / 3600 / 24);
283
+                            if ($days <= $refunddays) {
284
+                                $canrefund = true;
285
+                            }
286
+                        }
287
+                    }
288
+                }
289
+            }*/
290
+            $row['canrefund'] = $canrefund;
291
+            //是否可以核销
292
+            $row['canverify'] = false;
293
+
294
+            $canverify = false;
295
+
296
+            if ($com_verify) {
297
+                $showverify =  ($row['dispatchtype'] || $row['isverify']) && !$row['isonlyverifygoods'] ;
298
+                if ($row['isverify']) {
299
+
300
+                    if(!$row['isonlyverifygoods']) {
301
+
302
+                        if ($row['verifytype'] == 0 || $row['verifytype'] == 1 || $row['verifytype'] == 3) {
303
+                            $vs = iunserializer($row['verifyinfo']);
304
+                            $verifyinfo = array(
305
+                                array(
306
+                                    'verifycode' => $row['verifycode'],
307
+                                    'verified' => $row['verifytype'] == 0 ? $row['verified'] : count($vs) >= $row['goods'][0]['goods']['total']
308
+                                )
309
+                            );
310
+                            if ($row['verifytype'] == 0 || $row['verifytype'] == 3) {
311
+                                $canverify = empty($row['verified']) && $showverify;
312
+                            } else if ($row['verifytype'] == 1) {
313
+                                $canverify = count($vs) < $row['goods'][0]['goods']['total'] && $showverify;
314
+                            }
315
+
316
+                        } else {
317
+
318
+                            $verifyinfo = iunserializer($row['verifyinfo']);
319
+
320
+                            $last = 0;
321
+                            foreach ($verifyinfo as $v) {
322
+                                if (!$v['verified']) {
323
+                                    $last++;
324
+                                }
325
+                            }
326
+                            $canverify = $last > 0 && $showverify;
327
+                        }
328
+                    }
329
+
330
+                } else if (!empty($row['dispatchtype'])) {
331
+                    $canverify = $row['status'] == 1 && $showverify;
332
+                }
333
+            }
334
+
335
+            $row['canverify']  = $canverify;
336
+
337
+            if ($is_openmerch == 1) {
338
+                $row['merchname'] = $merch_user[$row['merchid']]['merchname'] ? $merch_user[$row['merchid']]['merchname'] : $_W['shopset']['shop']['name'];
339
+            }
340
+
341
+            if($row['isonlyverifygoods']){
342
+
343
+                $row['canverify'] = false;
344
+                $verifygood = pdo_fetch("select * from ".tablename('ewei_shop_verifygoods').' where orderid=:orderid limit 1',array(':orderid'=>$row['id']));
345
+                if(!empty($verifygood)){
346
+                    $row['verifygoods_id'] = $verifygood['id'];
347
+                    //剩余次数
348
+                    $verifynum = pdo_fetchcolumn('select sum(verifynum) from ' . tablename('ewei_shop_verifygoods_log') . '    where verifygoodsid =:id  ', array(':id' => $verifygood['id']));
349
+                    //是否过期
350
+                    if(empty($verifygood['limittype']))
351
+                    {
352
+                        $limitdate = intval($verifygood['starttime']) +  intval($verifygood['limitdays'])*86400;
353
+
354
+                    }else
355
+                    {
356
+                        $limitdate = intval($verifygood['limitdate']);
357
+                    }
358
+                    $row['canverify']  = $limitdate>=time() ;
359
+                    if( $verifygood['limitnum']>0){
360
+                        $row['canverify'] = $verifynum < $verifygood['limitnum'];
361
+                    }
362
+                }
363
+            }
364
+        }
365
+        unset($row);
366
+
367
+        show_json(1,array('list'=>$list,'pagesize'=>$psize,'total'=>$total));
368
+    }
369
+
370
+    function alipay() {
371
+        global $_W, $_GPC;
372
+        $url = urldecode($_GPC['url']);
373
+        if(!is_weixin()){
374
+            header('location: ' . $url);
375
+            exit;
376
+        }
377
+        include $this->template();
378
+    }
379
+
380
+    function detail() {
381
+
382
+        global $_W, $_GPC;
383
+        $openid = $_W['openid'];
384
+        $uniacid = $_W['uniacid'];
385
+        $member = m('member')->getMember($openid, true);
386
+        $orderid = intval($_GPC['id']);
387
+        $ispeerpay = m('order')->checkpeerpay($orderid);//检查是否是代付订单
388
+        // 判断进入订单详情 返回键隐藏
389
+        $isshow = $_GPC['isshow'];
390
+        if (empty($orderid)) {
391
+            header('location: ' . mobileUrl('order'));
392
+            exit;
393
+        }
394
+
395
+
396
+        $order = pdo_fetch("select * from " . tablename('ewei_shop_order') . ' where id=:id and uniacid=:uniacid and openid=:openid limit 1'
397
+            , array(':id' => $orderid, ':uniacid' => $uniacid, ':openid' => $openid));
398
+
399
+        //如果是周期购订单则跳转周期购商品详情
400
+        if($order['iscycelbuy'] == 1) {
401
+            header("location:" . mobileUrl('cycelbuy/order/detail', array('id' => $order['id'])));
402
+        }
403
+
404
+        if (empty($order)) {
405
+            header('location: ' . mobileUrl('order'));
406
+            exit;
407
+        }
408
+
409
+        if ($order['merchshow'] == 1) {
410
+            header('location: ' . mobileUrl('order'));
411
+            exit;
412
+        }
413
+
414
+        if ($order['userdeleted'] == 2) {
415
+            $this->message('订单已经被删除!','','error');
416
+        }
417
+
418
+        if (!empty($order['istrade'])) {
419
+            header('location: ' . mobileUrl('newstore/norder/detail', array('id' => $orderid)));
420
+            exit;
421
+        }
422
+
423
+        $isonlyverifygoods = m('order')->checkisonlyverifygoods($order['id']);
424
+
425
+//        if ($order['isnewstore'] == 1) {
426
+//            $store_item = m('store')->getStoreInfo($order['storeid']);
427
+//        }
428
+
429
+
430
+        //如果维过权则取维权信息
431
+        if($order['refundid'] !=0){
432
+            $refund = pdo_fetch("SELECT *  FROM " . tablename('ewei_shop_order_refund') . " WHERE orderid = :orderid and uniacid=:uniacid order by id desc", array(':orderid' => $order['id'], ':uniacid' => $_W['uniacid']));
433
+        }
434
+//        print_r($refund);die();
435
+
436
+        $area_set = m('util')->get_area_config_set();
437
+        $new_area = intval($area_set['new_area']);
438
+        $address_street = intval($area_set['address_street']);
439
+
440
+        //多商户
441
+        $merchdata = $this->merchData();
442
+        extract($merchdata);
443
+
444
+        $merchid = $order['merchid'];
445
+        //商品信息
446
+        $diyform_plugin = p('diyform');
447
+        $diyformfields = "";
448
+        if ($diyform_plugin) {
449
+            $diyformfields = ",og.diyformfields,og.diyformdata";
450
+        }
451
+
452
+        $param = array();
453
+        $param[':uniacid'] = $_W['uniacid'];
454
+
455
+        if ($order['isparent'] == 1) {
456
+            $scondition = " og.parentorderid=:parentorderid";
457
+            $param[':parentorderid'] = $orderid;
458
+        } else {
459
+            $scondition = " og.orderid=:orderid";
460
+            $param[':orderid'] = $orderid;
461
+        }
462
+
463
+        $condition1 = '';
464
+        if(p('ccard')) {
465
+            $condition1 .= ',g.ccardexplain,g.ccardtimeexplain';
466
+        }
467
+
468
+        $goodsid_array =array();
469
+        $goods = pdo_fetchall("select og.id,og.single_refundstate,og.sendtime,og.goodsid,og.price,g.title,og.title as gtitle,g.thumb,g.status, g.cannotrefund, og.total,g.credit,og.optionid,
470
+            og.optionname as optiontitle,g.isverify,g.storeids,og.seckill,g.isfullback,
471
+            og.seckill_taskid{$diyformfields}{$condition1},og.prohibitrefund  from " . tablename('ewei_shop_order_goods') . " og "
472
+            . " left join " . tablename('ewei_shop_goods') . " g on g.id=og.goodsid "
473
+            . " where $scondition and og.uniacid=:uniacid ", $param);
474
+
475
+		//禁止退款prohibit refund
476
+        $prohibitrefund=false;
477
+        $isfullback=false;
478
+        foreach($goods as &$g){
479
+            if($g['isfullback']){
480
+                $isfullback=true;
481
+                $fullbackgoods = pdo_fetch("SELECT * FROM ".tablename('ewei_shop_fullback_goods')." WHERE goodsid = :goodsid and uniacid = :uniacid  limit 1 ",array(':goodsid'=>$g['goodsid'],':uniacid'=>$uniacid));
482
+                if($g['optionid']){
483
+                    $option = pdo_fetch("select `day`,allfullbackprice,fullbackprice,allfullbackratio,fullbackratio,isfullback
484
+                      from ".tablename('ewei_shop_goods_option')." where id = :id and uniacid = :uniacid ",array(":id"=>$g['optionid'],":uniacid"=>$uniacid));
485
+                    $fullbackgoods['minallfullbackallprice'] = $option['allfullbackprice'];
486
+                    $fullbackgoods['fullbackprice'] = $option['fullbackprice'];
487
+                    $fullbackgoods['minallfullbackallratio'] = $option['allfullbackratio'];
488
+                    $fullbackgoods['fullbackratio'] = $option['fullbackratio'];
489
+                    $fullbackgoods['day'] = $option['day'];
490
+                }
491
+                $g['fullbackgoods'] = $fullbackgoods;
492
+                unset($fullbackgoods,$option);
493
+            }
494
+
495
+            $g['seckill_task'] = false;
496
+            if($g['seckill']){
497
+                $g['seckill_task'] = plugin_run('seckill::getTaskInfo',$g['seckill_taskid']);
498
+            }
499
+
500
+            if(!empty($g['prohibitrefund']))
501
+            {
502
+                $prohibitrefund=true;
503
+            }
504
+            if(empty($g['gtitle'])!=true){
505
+                $g['title']=$g['gtitle'];
506
+            }
507
+        }
508
+        unset($g);
509
+        //商品是否支持退换货
510
+        $goodsrefund = true;
511
+
512
+        if(!empty($goods)) {
513
+            foreach ($goods as &$g) {
514
+                $goodsid_array[] = $g['goodsid'];
515
+                if (!empty($g['optionid'])) {
516
+                    $thumb = m('goods')->getOptionThumb($g['goodsid'], $g['optionid']);
517
+                    if (!empty($thumb)) {
518
+                        $g['thumb'] = $thumb;
519
+                    }
520
+                }
521
+                if(!empty($g['cannotrefund']) && $order['status']==2){
522
+                    $goodsrefund = false;
523
+                }
524
+            }
525
+            unset($g);
526
+        }
527
+        $diyform_flag = 0;
528
+
529
+        if ($diyform_plugin) {
530
+            foreach ($goods as &$g) {
531
+                $g['diyformfields'] = iunserializer($g['diyformfields']);
532
+                $g['diyformdata'] = iunserializer($g['diyformdata']);
533
+                unset($g);
534
+            }
535
+
536
+            //订单统一模板
537
+            if (!empty($order['diyformfields']) && !empty($order['diyformdata'])) {
538
+                $order_fields = iunserializer($order['diyformfields']);
539
+                $order_data = iunserializer($order['diyformdata']);
540
+            }
541
+        }
542
+
543
+        //收货地址
544
+        $address = false;
545
+        if (!empty($order['addressid'])) {
546
+            $address = iunserializer($order['address']);
547
+            if (!is_array($address)) {
548
+                $address = pdo_fetch('select * from  ' . tablename('ewei_shop_member_address') . ' where id=:id limit 1', array(':id' => $order['addressid']));
549
+            }
550
+        }
551
+
552
+        //联系人
553
+        $carrier = @iunserializer($order['carrier']);
554
+        if (!is_array($carrier) || empty($carrier)) {
555
+            $carrier = false;
556
+        }
557
+
558
+        //门店
559
+        $store = false;
560
+        if (!empty($order['storeid'])) {
561
+
562
+            if ($merchid > 0) {
563
+                $store = pdo_fetch('select * from  ' . tablename('ewei_shop_merch_store') . ' where id=:id limit 1', array(':id' => $order['storeid']));
564
+
565
+            } else {
566
+                $store = pdo_fetch('select * from  ' . tablename('ewei_shop_store') . ' where id=:id limit 1', array(':id' => $order['storeid']));
567
+            }
568
+        }
569
+
570
+        //核销门店
571
+        $stores = false;
572
+        $showverify = false;  //是否显示消费码
573
+        $canverify = false;  //是否可以核销
574
+        $verifyinfo = false;
575
+        if (com('verify')) {
576
+            $showverify = ( $order['dispatchtype'] || $order['isverify'] ) ;
577
+
578
+            if ($order['isverify']) {
579
+                //lynn核销限制时间判断
580
+                if($order['verifyendtime'] > 0 && $order['verifyendtime'] < time()){
581
+                    $order['status'] = -1;
582
+                }
583
+                //核销单
584
+                $storeids = array();
585
+                foreach ($goods as $g) {
586
+                    if (!empty($g['storeids'])) {
587
+                        $storeids = array_merge(explode(',', $g['storeids']), $storeids);
588
+                    }
589
+                }
590
+
591
+                if (empty($storeids)) {
592
+                    //全部门店
593
+                    if ($merchid > 0) {
594
+                        $stores = pdo_fetchall('select * from ' . tablename('ewei_shop_merch_store') . ' where  uniacid=:uniacid and merchid=:merchid and status=1 and type in(2,3)', array(':uniacid' => $_W['uniacid'], ':merchid' => $merchid));
595
+                    } else {
596
+                        $stores = pdo_fetchall('select * from ' . tablename('ewei_shop_store') . ' where  uniacid=:uniacid and status=1 and type in(2,3)', array(':uniacid' => $_W['uniacid']));
597
+                    }
598
+                } else {
599
+                    if ($merchid > 0) {
600
+                        $stores = pdo_fetchall('select * from ' . tablename('ewei_shop_merch_store') . ' where id in (' . implode(',', $storeids) . ') and uniacid=:uniacid and merchid=:merchid and status=1 and type in(2,3)', array(':uniacid' => $_W['uniacid'], ':merchid' => $merchid));
601
+                    } else {
602
+                        $stores = pdo_fetchall('select * from ' . tablename('ewei_shop_store') . ' where id in (' . implode(',', $storeids) . ') and uniacid=:uniacid and status=1 and type in(2,3)', array(':uniacid' => $_W['uniacid']));
603
+                    }
604
+                }
605
+
606
+
607
+//                print_r($stores);exit;
608
+
609
+
610
+                if ($order['verifytype'] == 0 || $order['verifytype'] == 1 || $order['verifytype'] == 3) {
611
+                    $vs = iunserializer($order['verifyinfo']);
612
+                    $verifyinfo = array(
613
+                        array(
614
+                            'verifycode' => $order['verifycode'],
615
+                            'verified' => $order['verifytype'] == 0 || $order['verifytype'] == 3 ?$order['verified']: count($vs)>=$goods[0]['total']
616
+                        )
617
+                    );
618
+                    if( $order['verifytype']==0 || $order['verifytype'] == 3) {
619
+                        $canverify = empty($order['verified']) && $showverify;
620
+                    } else if( $order['verifytype']==1 ){
621
+                        $canverify = count($vs)<$goods[0]['total']  && $showverify;
622
+                    }
623
+
624
+                } else {
625
+                    $verifyinfo = iunserializer($order['verifyinfo']);
626
+
627
+                    $last = 0;
628
+                    foreach($verifyinfo as $v){
629
+                        if(!$v['verified']){
630
+                            $last++;
631
+                        }
632
+                    }
633
+                    $canverify = $last>0 && $showverify;
634
+                }
635
+            }
636
+            else if(!empty($order['dispatchtype'])){
637
+
638
+                $verifyinfo = array(
639
+                    array(
640
+                        'verifycode' => $order['verifycode'],
641
+                        'verified' => $order['status'] == 3
642
+                    )
643
+                );
644
+
645
+                $canverify = $order['status']==1 && $showverify;
646
+            }
647
+
648
+        }
649
+        $order['canverify'] = $canverify;
650
+        $order['showverify'] = $showverify;
651
+
652
+        //虚拟物品信息
653
+        $order['virtual_str'] = str_replace("\n", "<br/>", $order['virtual_str']);
654
+        $canreturn = false;
655
+        //是否可以退款
656
+        $tradeset = m('common')->getSysset('trade');
657
+        if ($order['status'] == 1 || $order['status'] == 2) {
658
+            $canrefund = true;
659
+            if ($order['status'] == 2 && $order['price'] == $order['dispatchprice']) {
660
+                if ($order['refundstate'] > 0) {
661
+                    $canrefund = true;
662
+                } else {
663
+                    $canrefund = false;
664
+                    //当产品余额抵扣所有金额的时候 允许换货
665
+                    if(!$goodsrefund){
666
+                        //当产品不允许退换货而且抵扣了所有金额之后不显示 退款
667
+                        $canreturn = false;
668
+                    }else{
669
+                        $canreturn = true;
670
+                    }
671
+                }
672
+            }
673
+        } else if ($order['status'] == 3) {
674
+            if ($order['isverify'] != 1 && empty($order['virtual'])) { //如果不是核销或虚拟物品,则可以退货
675
+                if ($order['refundstate'] > 0) {
676
+                    $canrefund = true;
677
+                } else {
678
+
679
+                    $refunddays = intval($tradeset['refunddays']);
680
+
681
+                    if ($refunddays > 0) {
682
+                        $days = intval((time() - $order['finishtime']) / 3600 / 24);
683
+                        if ($days <= $refunddays) {
684
+                            $canrefund = true;
685
+                        }
686
+                    }
687
+                }
688
+            }
689
+
690
+        }
691
+
692
+        if (!empty($order['isnewstore']) && $order['status'] > 1) {
693
+            $canrefund = false;
694
+        }
695
+		if($prohibitrefund)
696
+        {
697
+            $canrefund = false;
698
+        }
699
+
700
+        if(!$goodsrefund && $canrefund){
701
+            $canrefund = false;
702
+        }
703
+
704
+
705
+        if(p('ccard')) {
706
+
707
+            if(!empty($order['ccard']) && $order['status'] > 1) {
708
+                $canrefund = false;
709
+            }
710
+
711
+            $comdata = m('common')->getPluginset('commission');
712
+            if (!empty($comdata['become_goodsid']) && !empty($goodsid_array)) {
713
+                if(in_array($comdata['become_goodsid'], $goodsid_array)) {
714
+                    $canrefund = false;
715
+                }
716
+            }
717
+        }
718
+
719
+        $haveverifygoodlog = m('order')->checkhaveverifygoodlog($orderid);
720
+        if($haveverifygoodlog)
721
+        {
722
+            $canrefund = false;
723
+        }
724
+
725
+        $order['canrefund'] = $canrefund;
726
+
727
+        //如果发货,查找第一条物流
728
+        $express = false;
729
+        $order_goods = array();
730
+        if ($order['status'] >= 2 && empty($order['isvirtual']) && empty($order['isverify'])) {
731
+            $expresslist = m('util')->getExpressList($order['express'], $order['expresssn']);
732
+            if (count($expresslist) > 0) {
733
+                $express = $expresslist[0];
734
+            }
735
+        }
736
+        if($order['sendtype']>0 && $order['status']>=1){
737
+            $order_goods = pdo_fetchall("select orderid,goodsid,sendtype,expresscom,expresssn,express,sendtime from ".tablename('ewei_shop_order_goods')."
738
+            where orderid = ".$orderid." and uniacid = ".$uniacid." and sendtype > 0 group by sendtype order by sendtime asc ");
739
+            $expresslist = m('util')->getExpressList($order['express'], $order['expresssn']);
740
+            if (count($expresslist) > 0) {
741
+                $express = $expresslist[0];
742
+            }
743
+            $order['sendtime'] = $order_goods[0]['sendtime'];
744
+        }
745
+        $shopname = $_W['shopset']['shop']['name'];
746
+
747
+        //显示核销码
748
+        if( $order['canverify']&&$order['status']!=-1&&$order['status']!=0)
749
+        {
750
+            $query = array('id' => $order['id'], 'verifycode' => $order['verifycode']);
751
+
752
+            if( !$isonlyverifygoods) {
753
+                if (empty($order['istrade'])) {
754
+                    $url = mobileUrl('verify/detail', $query, true);
755
+                } else {
756
+                    $url = mobileUrl('verify/tradedetail', $query, true);
757
+                }
758
+                $verifycode = $order['verifycode'];
759
+                $qrcodeimg = m('qrcode')->createQrcode($url);
760
+
761
+                if(strlen($verifycode)==8)
762
+                {
763
+                    $verifycode= substr($verifycode,0,4)." ".substr($verifycode,4,4);
764
+                }
765
+                else if(strlen($verifycode)==9)
766
+                {
767
+                    $verifycode= substr($verifycode,0,3)." ".substr($verifycode,3,3)." ".substr($verifycode,6,3);
768
+                }
769
+            }
770
+
771
+
772
+        }
773
+
774
+
775
+
776
+        if (!empty($order['merchid']) && $is_openmerch == 1)
777
+        {
778
+            $merch_user = $merch_plugin->getListUser($order['merchid']);
779
+            $shopname = $merch_user['merchname'];
780
+            $shoplogo = tomedia($merch_user['logo']);
781
+        }
782
+
783
+        if(com('coupon')){
784
+            $activity = com('coupon') -> activity($order['price']);
785
+        }
786
+        
787
+        // 虚拟卡密
788
+        if(!empty($order['virtual']) && !empty($order['virtual_str'])){
789
+            $ordervirtual = m('order')->getOrderVirtual($order);
790
+            $virtualtemp = pdo_fetch('SELECT linktext, linkurl,description FROM '. tablename('ewei_shop_virtual_type'). ' WHERE id=:id AND uniacid=:uniacid LIMIT 1', array(':id'=>$order['virtual'], ':uniacid'=>$_W['uniacid']));
791
+        }
792
+
793
+        //秒杀风格色
794
+        if($order['seckilldiscountprice']>0&& p('diypage')){
795
+            $diypagedata = m('common')->getPluginset('diypage');
796
+            $diypage = p('diypage')->seckillPage($diypagedata['seckill']);
797
+            if(!empty($diypage)){
798
+                $seckill_color=$diypage['seckill_color'];
799
+            }
800
+        }
801
+
802
+        //判断是否使用会员卡
803
+        $use_membercard = false;
804
+        $membercard_info = array();
805
+        $plugin_membercard = p('membercard');
806
+        if($plugin_membercard){
807
+            $ifuse = $plugin_membercard->if_order_use_membercard($orderid);
808
+            if($ifuse){
809
+                $use_membercard = true;
810
+                $card_text = $ifuse['name'].'优惠';
811
+                $card_dec_price = $ifuse['dec_price'];
812
+            }
813
+        }
814
+
815
+        // 虚拟商品自动发货不能退款
816
+        if ($order['isvirtualsend'] && $order['isvirtual']) {
817
+            $order['canrefund'] = false;
818
+        }
819
+
820
+        //是否显示单品退换 (不是套餐 && 不是代付 && 不是全返 && 开启了单品退换开关) || 订单维权状态==单品维权
821
+        if((empty($order['ispackage']) && empty($ispeerpay) && empty($isfullback) && !empty($tradeset['single_refund'])) || $order['refundstate']==3){
822
+            $is_single_refund=true;
823
+        }else{
824
+            $is_single_refund=false;
825
+        }
826
+
827
+        include $this->template();
828
+    }
829
+
830
+    function express() {
831
+        global $_W, $_GPC;
832
+
833
+        global $_W, $_GPC;
834
+        $openid = $_W['openid'];
835
+        $uniacid = $_W['uniacid'];
836
+        $orderid = intval($_GPC['id']);
837
+        $sendtype = intval($_GPC['sendtype']);
838
+        $bundle = trim($_GPC['bundle']);
839
+
840
+
841
+        if (empty($orderid)) {
842
+            header('location: ' . mobileUrl('order'));
843
+            exit;
844
+        }
845
+        $order = pdo_fetch("select * from " . tablename('ewei_shop_order') . ' where id=:id and uniacid=:uniacid and openid=:openid limit 1'
846
+            , array(':id' => $orderid, ':uniacid' => $uniacid, ':openid' => $openid));
847
+        if (empty($order)) {
848
+            header('location: ' . mobileUrl('order'));
849
+            exit;
850
+        }
851
+        $bundlelist = array();
852
+        if($order['sendtype']>0 && $sendtype == 0){
853
+            for($i=1;$i<=intval($order['sendtype']);$i++){
854
+                $bundlelist[$i]['sendtype'] = $i;
855
+                $bundlelist[$i]['orderid'] = $orderid;
856
+                $bundlelist[$i]['goods'] = pdo_fetchall("select g.title,g.thumb,og.total,og.optionname as optiontitle,og.expresssn,og.express,
857
+                    og.sendtype,og.expresscom,og.sendtime from " . tablename('ewei_shop_order_goods') . " og "
858
+                    . " left join " . tablename('ewei_shop_goods') . " g on g.id=og.goodsid "
859
+                    . " where og.orderid=:orderid and og.sendtype = ".$i." and og.uniacid=:uniacid ", array(':uniacid' => $uniacid, ':orderid' => $orderid));
860
+                if(empty($bundlelist[$i]['goods'])){
861
+                    unset($bundlelist[$i]);
862
+                }
863
+            }
864
+            $bundlelist = array_values($bundlelist);
865
+        }
866
+        if (empty($order['addressid'])) {
867
+            $this->message('订单非快递单,无法查看物流信息!');
868
+        }
869
+        if (!($order['status'] >= 2) && !($order['status']>=1 && $order['sendtype']>0)) {
870
+            $this->message('订单未发货,无法查看物流信息!');
871
+        }
872
+        $condition = '';
873
+        //商品信息
874
+        if($sendtype>0){
875
+            $condition = ' and og.sendtype = '.$sendtype;
876
+        }
877
+        $goods = pdo_fetchall("select og.goodsid,og.price,g.title,g.thumb,og.total,g.credit,og.optionid,og.optionname as optiontitle,g.isverify,og.expresssn,og.express,
878
+            og.sendtype,og.expresscom,og.sendtime,g.storeids{$diyformfields}
879
+            from " . tablename('ewei_shop_order_goods') . " og "
880
+            . " left join " . tablename('ewei_shop_goods') . " g on g.id=og.goodsid "
881
+            . " where og.orderid=:orderid and og.single_refundtime=0 ".$condition." and og.uniacid=:uniacid ", array(':uniacid' => $uniacid, ':orderid' => $orderid));
882
+        if($sendtype>0){
883
+            $order['express'] = $goods[0]['express'];
884
+            $order['expresssn'] = $goods[0]['expresssn'];
885
+            $order['expresscom'] = $goods[0]['expresscom'];
886
+        }
887
+        $expresslist = m('util')->getExpressList($order['express'], $order['expresssn']);
888
+
889
+        include $this->template();
890
+    }
891
+
892
+    function dispatch() {
893
+        global $_W, $_GPC;
894
+
895
+        $merchid = intval($_GPC['merchid']);
896
+
897
+        $list = m('dispatch')->getDispatchList($merchid);
898
+
899
+        include $this->template();
900
+
901
+    }
902
+}

+ 217 - 0
addons/ewei_shopv2/core/mobile/order/op.php Parādīt failu

@@ -0,0 +1,217 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+    exit('Access Denied');
4
+}
5
+
6
+class Op_EweiShopV2Page extends MobileLoginPage {
7
+
8
+    /**
9
+     * 取消订单
10
+     * @global type $_W
11
+     * @global type $_GPC
12
+     */
13
+    function cancel() {
14
+
15
+        global $_W, $_GPC;
16
+        $orderid = intval($_GPC['id']);
17
+        $order = pdo_fetch("select id,ordersn,openid,status,deductcredit,deductcredit2,deductprice,couponid,isparent,`virtual`,`virtual_info`,merchid from " . tablename('ewei_shop_order') . ' where id=:id and uniacid=:uniacid and openid=:openid limit 1'
18
+            , array(':id' => $orderid, ':uniacid' => $_W['uniacid'], ':openid' => $_W['openid']));
19
+        if (empty($order)) {
20
+            show_json(0, '订单未找到');
21
+        }
22
+        if($order['status'] > 0){
23
+            show_json(0, '订单已支付,不能取消!');
24
+        }
25
+        if($order['status'] < 0){
26
+            show_json(0, '订单已经取消!');
27
+        }
28
+
29
+        if (!empty($order['virtual']) && $order['virtual'] != 0) {
30
+
31
+            $goodsid = pdo_fetch('SELECT goodsid FROM '.tablename('ewei_shop_order_goods').' WHERE uniacid = '.$_W['uniacid'].' AND orderid = '.$order['id']);
32
+
33
+            $typeid = $order['virtual'];
34
+            $vkdata = ltrim($order['virtual_info'],'[');
35
+            $vkdata = rtrim($vkdata,']');
36
+            $arr = explode('}',$vkdata);
37
+            foreach($arr as $k => $v){
38
+                if(!$v){
39
+                    unset($arr[$k]);
40
+                }
41
+            }
42
+            $vkeynum = count($arr);
43
+
44
+            //未付款卡密变为未使用
45
+            pdo_query("update " . tablename('ewei_shop_virtual_data') . ' set openid="",usetime=0,orderid=0,ordersn="",price=0,merchid='.$order['merchid'].' where typeid=' . intval($typeid).' and orderid = '.$order["id"]);
46
+
47
+            //模板减少使用数据
48
+            pdo_query("update " . tablename('ewei_shop_virtual_type') . " set usedata=usedata-".$vkeynum." where id=" .intval($typeid));
49
+
50
+        }
51
+
52
+        //处理订单库存及用户积分情况(赠送积分)
53
+        m('order')->setStocksAndCredits($orderid, 2);
54
+
55
+
56
+        //返还抵扣积分
57
+        if ($order['deductprice'] > 0) {
58
+            m('member')->setCredit($order['openid'], 'credit1', $order['deductcredit'], array('0', $_W['shopset']['shop']['name'] . "购物返还抵扣积分 积分: {$order['deductcredit']} 抵扣金额: {$order['deductprice']} 订单号: {$order['ordersn']}"));
59
+        }
60
+
61
+        //返还抵扣余额
62
+        m('order')->setDeductCredit2($order);
63
+
64
+        //退还优惠券 退还之前先检测
65
+        if (com('coupon') && !empty($order['couponid'])) {
66
+
67
+            //检测当前优惠券有没有使用过
68
+            $plugincoupon = com('coupon');
69
+            if ($plugincoupon) {
70
+                $coupondata=  $plugincoupon->getCouponByDataID($order['couponid']);
71
+                if($coupondata['used']!=1){
72
+                    com('coupon')->returnConsumeCoupon($orderid); //手机关闭订单
73
+                }
74
+            }
75
+
76
+        }
77
+
78
+        pdo_update('ewei_shop_order', array('status' => -1, 'canceltime' => time(), 'closereason' => trim($_GPC['remark'])), array('id' => $order['id'], 'uniacid' => $_W['uniacid']));
79
+
80
+
81
+        if (!empty($order['isparent'])) {
82
+            pdo_update('ewei_shop_order', array('status' => -1, 'canceltime' => time(), 'closereason' => trim($_GPC['remark'])), array('parentid' => $order['id'], 'uniacid' => $_W['uniacid']));
83
+        }
84
+
85
+        //模板消息
86
+        m('notice')->sendOrderMessage($orderid);
87
+
88
+        show_json(1);
89
+    }
90
+
91
+    /**
92
+     * 确认收货
93
+     * @global type $_W
94
+     * @global type $_GPC
95
+     */
96
+    function finish() {
97
+
98
+        global $_W, $_GPC;
99
+        $orderid = intval($_GPC['id']);
100
+
101
+        //单品退换货,确认收货后取消维权
102
+        pdo_update('ewei_shop_order_goods', array('single_refundstate' => 0), array('orderid' => $orderid, 'uniacid' => $_W['uniacid']));
103
+
104
+        $order = pdo_fetch("select id,status,openid,couponid,price,refundstate,refundid,ordersn,price from " . tablename('ewei_shop_order') . ' where id=:id and uniacid=:uniacid and openid=:openid limit 1'
105
+            , array(':id' => $orderid, ':uniacid' => $_W['uniacid'], ':openid' => $_W['openid']));
106
+        if (empty($order)) {
107
+            show_json(0, '订单未找到');
108
+        }
109
+        if ($order['status'] != 2) {
110
+            show_json(0, '订单不能确认收货');
111
+        }
112
+        if ($order['refundstate'] > 0 && !empty($order['refundid'])) {
113
+
114
+            $change_refund = array();
115
+            $change_refund['status'] = -2;
116
+            $change_refund['refundtime'] = time();
117
+            pdo_update('ewei_shop_order_refund', $change_refund, array('id' => $order['refundid'], 'uniacid' => $_W['uniacid']));
118
+        }
119
+
120
+        pdo_update('ewei_shop_order', array('status' => 3, 'finishtime' => time(), 'refundstate' => 0), array('id' => $order['id'], 'uniacid' => $_W['uniacid']));
121
+
122
+//        //处理积分
123
+        m('order')->setStocksAndCredits($orderid, 3);
124
+
125
+        //商品全返
126
+        m('order')->fullback($orderid);
127
+        //show_json(0, $res);
128
+
129
+        //会员升级
130
+        m('member')->upgradeLevel($order['openid'], $orderid);
131
+
132
+        //余额赠送
133
+        m('order')->setGiveBalance($orderid, 1);
134
+
135
+        //发送赠送优惠券
136
+        if (com('coupon')) {
137
+            $refurnid = com('coupon')->sendcouponsbytask($orderid); //订单支付
138
+        }
139
+
140
+        //优惠券返利
141
+        if (com('coupon') && !empty($order['couponid'])) {
142
+            com('coupon')->backConsumeCoupon($orderid); //手机收货
143
+        }
144
+
145
+        //模板消息
146
+        m('notice')->sendOrderMessage($orderid);
147
+
148
+        //打印机打印
149
+        com_run('printer::sendOrderMessage',$orderid);
150
+
151
+        //排队全返
152
+        if (p('lineup')) {
153
+            p('lineup')->checkOrder($order);
154
+        }
155
+
156
+        //分销检测
157
+        if (p('commission')) {
158
+            p('commission')->checkOrderFinish($orderid);
159
+        }
160
+        //抽奖
161
+        if(p('lottery')){
162
+            //type 1:消费 2:签到 3:任务 4:其他
163
+            $res = p('lottery')->getLottery($_W['openid'],1,array('money'=>$order['price'],'paytype'=>2));
164
+            if($res){
165
+                p('lottery')->getLotteryList($_W['openid'],array('lottery_id'=>$res));
166
+            }
167
+        }
168
+        // 任务中心
169
+        if (p('task')){
170
+            p('task')->checkTaskProgress($order['price'],'order_full','',$order['openid']);
171
+        }
172
+
173
+
174
+        show_json(1,array('url'=>mobileUrl('order',array('status'=>3))));
175
+    }
176
+
177
+    /**
178
+     * 删除或恢复订单
179
+     * @global type $_W
180
+     * @global type $_GPC
181
+     */
182
+    function delete() {
183
+        global $_W, $_GPC;
184
+
185
+        //删除订单
186
+        $orderid = intval($_GPC['id']);
187
+        $userdeleted = intval($_GPC['userdeleted']);
188
+
189
+        $order = pdo_fetch("select id,status,refundstate,refundid from " . tablename('ewei_shop_order') . ' where id=:id and uniacid=:uniacid and openid=:openid limit 1'
190
+            , array(':id' => $orderid, ':uniacid' => $_W['uniacid'], ':openid' => $_W['openid']));
191
+        if (empty($order)) {
192
+            show_json(0, '订单未找到!');
193
+        }
194
+
195
+        if ($userdeleted == 0) {
196
+            if ($order['status'] != 3) {
197
+                show_json(0, '无法恢复');
198
+            }
199
+        } else {
200
+            if ($order['status'] != 3 && $order['status'] != -1) {
201
+                show_json(0, '无法删除');
202
+            }
203
+
204
+            if ($order['refundstate'] > 0 && !empty($order['refundid'])) {
205
+
206
+                $change_refund = array();
207
+                $change_refund['status'] = -2;
208
+                $change_refund['refundtime'] = time();
209
+                pdo_update('ewei_shop_order_refund', $change_refund, array('id' => $order['refundid'], 'uniacid' => $_W['uniacid']));
210
+            }
211
+        }
212
+
213
+        pdo_update('ewei_shop_order', array('userdeleted' => $userdeleted, 'refundstate' => 0), array('id' => $order['id'], 'uniacid' => $_W['uniacid']));
214
+        show_json(1);
215
+    }
216
+
217
+}

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1423 - 0
addons/ewei_shopv2/core/mobile/order/pay.php


+ 253 - 0
addons/ewei_shopv2/core/mobile/order/pay_alipay.php Parādīt failu

@@ -0,0 +1,253 @@
1
+<?php
2
+
3
+if (!defined('IN_IA')) {
4
+    exit('Access Denied');
5
+}
6
+
7
+class Pay_Alipay_EweiShopV2Page extends MobilePage {
8
+
9
+    function main()
10
+    {
11
+        global $_W, $_GPC;
12
+        $url = urldecode($_GPC['url']);
13
+        if(!is_weixin()){
14
+            header('location: ' . $url);
15
+            exit;
16
+        }
17
+
18
+        include $this->template('order/alipay');
19
+    }
20
+
21
+    public function complete() {
22
+        global $_GPC, $_W;
23
+
24
+        $set = m('common')->getSysset(array('shop', 'pay'));
25
+
26
+        $fromwechat = intval($_GPC['fromwechat']);
27
+        $tid = $_GPC['out_trade_no'];
28
+
29
+        if(is_h5app()){
30
+            $sec = m('common')->getSec();
31
+            $sec =iunserializer($sec['sec']);
32
+
33
+            $alidata = base64_decode($_GET['alidata']);
34
+            $alidata = json_decode($alidata, true);
35
+            $sign_type = trim($alidata['sign_type'],'"');
36
+            if($sign_type == 'RSA'){
37
+                $public_key = $sec['app_alipay']['public_key'];
38
+            }else if($sign_type == 'RSA2'){
39
+                $public_key = $sec['app_alipay']['public_key_rsa2'];
40
+            }
41
+
42
+            if(empty($set['pay']['app_alipay']) || empty($public_key)){
43
+                $this->message('支付出现错误,请重试(1)!', mobileUrl('order'));
44
+            }
45
+
46
+            $alisign = m('finance')->RSAVerify($alidata, $public_key, false);
47
+
48
+            $tid = $this->str($alidata['out_trade_no']);
49
+
50
+            if($alisign==0){
51
+                $this->message('支付出现错误,请重试(2)!', mobileUrl('order'));
52
+            }
53
+
54
+            if (strexists($tid, 'GJ')) {
55
+                $tids = explode("GJ", $tid);
56
+                $tid = $tids[0];
57
+            }
58
+
59
+        }else{
60
+            if(empty($set['pay']['alipay'])){
61
+                $this->message('未开启支付宝支付!', mobileUrl('order'));
62
+            }
63
+            if (!m('finance')->isAlipayNotify($_GET)) {
64
+                $log = pdo_fetch('SELECT * FROM ' . tablename('core_paylog') . ' WHERE `uniacid`=:uniacid AND `module`=:module AND `tid`=:tid limit 1', array(':uniacid' => $_W['uniacid'], ':module' => 'ewei_shopv2', ':tid' => $tid));
65
+                if($log['status']==1 && $log['fee']==$_GPC['total_fee']){
66
+                    if($fromwechat){
67
+                        $this->message(array("message"=>"请返回微信查看支付状态", "title"=>"支付成功!", "buttondisplay"=>false), null, 'success');
68
+                    }else{
69
+                        $this->message(array("message"=>"请返回商城查看支付状态", "title"=>"支付成功!"), mobileUrl('order'), 'success');
70
+                    }
71
+                }
72
+                $this->message(array('message'=>'支付出现错误,请重试(支付验证失败)!', 'buttondisplay'=>$fromwechat?false:true), $fromwechat?null:mobileUrl('order'));
73
+            }
74
+        }
75
+
76
+        $log = pdo_fetch('SELECT * FROM ' . tablename('core_paylog') . ' WHERE `uniacid`=:uniacid AND `module`=:module AND `tid`=:tid limit 1', array(':uniacid' => $_W['uniacid'], ':module' => 'ewei_shopv2', ':tid' => $tid));
77
+
78
+
79
+        if (empty($log)) {
80
+            $this->message(array('message'=>'支付出现错误,请重试(支付验证失败2)!', 'buttondisplay'=>$fromwechat?false:true), $fromwechat?null:mobileUrl('order'));
81
+        }
82
+
83
+        if(is_h5app()){
84
+            $alidatafee = $this->str($alidata['total_fee']);
85
+            $alidatastatus = $this->str($alidata['success']);
86
+            if($log['fee']!=$alidatafee || !$alidatastatus){
87
+                $this->message('支付出现错误,请重试(4)!', mobileUrl('order'));
88
+            }
89
+        }
90
+
91
+        //同步回调弃用
92
+//        if ($log['status'] != 1) {
93
+//            //支付宝支付
94
+//            $record = array();
95
+//            $record['status'] = '1';
96
+//            $record['type'] = 'alipay';
97
+//            pdo_update('core_paylog', $record, array('plid' => $log['plid']));
98
+//
99
+//            //取orderid
100
+            $orderid = pdo_fetchcolumn('select id from ' . tablename('ewei_shop_order') . ' where ordersn=:ordersn and uniacid=:uniacid', array(':ordersn' => $log['tid'], ':uniacid' => $_W['uniacid']));
101
+//
102
+//            if (!empty($orderid))  {
103
+//                m('order')->setOrderPayType($orderid, 22);
104
+//                $data_alipay = array(
105
+//                    'transid' => $_GET['trade_no']
106
+//                );
107
+//                if(is_h5app()){
108
+//                    $data_alipay['transid'] = $alidata['trade_no'];
109
+//                    $data_alipay['apppay'] = 1;
110
+//                }
111
+//                pdo_update('ewei_shop_order', $data_alipay, array('id' => $orderid ));
112
+//            }
113
+//
114
+//            $ret = array();
115
+//            $ret['result'] = 'success';
116
+//            $ret['type'] = 'alipay';
117
+//            $ret['from'] = 'return';
118
+//            $ret['tid'] = $log['tid'];
119
+//            $ret['user'] = $log['openid'];
120
+//            $ret['fee'] = $log['fee'];
121
+//            $ret['weid'] = $log['weid'];
122
+//            $ret['uniacid'] = $log['uniacid'];
123
+//            m('order')->payResult($ret);
124
+//        }
125
+
126
+
127
+        if(is_h5app()){
128
+            $url = mobileUrl('order/detail', array('id' => $orderid),true);
129
+            die("<script>top.window.location.href='{$url}'</script>");
130
+        }else{
131
+            if($fromwechat) {
132
+                $this->message(array("message" => "请返回微信查看支付状态", "title" => "支付成功!", "buttondisplay" => false), null, 'success');
133
+            }else{
134
+                $this->message(array("message"=>"请返回商城查看支付状态", "title"=>"支付成功!"), mobileUrl('order'), 'success');
135
+            }
136
+        }
137
+
138
+    }
139
+
140
+
141
+    function recharge_complete() {
142
+        global $_W, $_GPC;
143
+
144
+        $fromwechat = intval($_GPC['fromwechat']);
145
+
146
+        //$this->message("121212");
147
+        $logno = trim($_GPC['out_trade_no']);
148
+        $notify_id = trim($_GPC['notify_id']); //支付宝通知ID
149
+        $sign = trim($_GPC['sign']);
150
+        $set = m('common')->getSysset(array('shop', 'pay'));
151
+        if(is_h5app()){
152
+            $sec = m('common')->getSec();
153
+            $sec =iunserializer($sec['sec']);
154
+
155
+            if(empty($_GET['alidata'])){
156
+                $this->message('支付出现错误,请重试(1)!', mobileUrl('member'));
157
+            }
158
+
159
+            $alidata = base64_decode($_GET['alidata']);
160
+            $alidata = json_decode($alidata, true);
161
+            $sign_type = $alidata['sign_type'];
162
+            if($sign_type == 'RSA'){
163
+                $public_key = $sec['app_alipay']['public_key'];
164
+            }else if($sign_type == 'RSA2'){
165
+                $public_key = $sec['app_alipay']['public_key_rsa2'];
166
+            }
167
+
168
+            if(empty($set['pay']['app_alipay']) || empty($public_key)){
169
+                $this->message('支付出现错误,请重试(2)!', mobileUrl('order'));
170
+            }
171
+
172
+            $alisign = m('finance')->RSAVerify($alidata, $public_key, false);
173
+
174
+            $logno = $this->str($alidata['out_trade_no']);
175
+
176
+            if($alisign==0){
177
+                $this->message('支付出现错误,请重试(3)!', mobileUrl('member'));
178
+            }
179
+            $transid=$alidata['trade_no'];
180
+        }else{
181
+
182
+            if (empty($logno)) {
183
+                $this->message(array('message'=>'支付出现错误,请重试(支付验证失败1)!', 'buttondisplay'=>$fromwechat?false:true), $fromwechat?null:mobileUrl('member'));
184
+            }
185
+
186
+            if(empty($set['pay']['alipay'])){
187
+                $this->message(array('message'=>'支付出现错误,请重试(未开启支付宝支付)!', 'buttondisplay'=>$fromwechat?false:true), $fromwechat?null:mobileUrl('member'));
188
+            }
189
+
190
+            if (!m('finance')->isAlipayNotify($_GET)) {
191
+                $log = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_member_log') . ' WHERE `logno`=:logno and `uniacid`=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':logno' => $logno));
192
+                if (!empty($log) && !empty($log['status'])) {
193
+                    if($fromwechat){
194
+                        $this->message(array("message"=>"请返回微信查看支付状态", "title"=>"支付成功!", "buttondisplay"=>false), null, 'success');
195
+                    }else{
196
+                        $this->message(array("message"=>"请返回商城查看支付状态", "title"=>"支付成功!"), mobileUrl('member'), 'success');
197
+                    }
198
+                }
199
+                $this->message(array('message'=>'支付出现错误,请重试(支付验证失败2)!', 'buttondisplay'=>$fromwechat?false:true), $fromwechat?null:mobileUrl('member'));
200
+            }
201
+            $transid=$_GET['trade_no'];
202
+        }
203
+
204
+        $log = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_member_log') . ' WHERE `logno`=:logno and `uniacid`=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':logno' => $logno));
205
+
206
+        //同步回调弃用
207
+//        if (!empty($log) && empty($log['status'])) {
208
+//
209
+//            //充值状态
210
+//            pdo_update('ewei_shop_member_log', array('status' => 1, 'rechargetype' => 'alipay', 'apppay'=>is_h5app()?1:0,'transid'=>$transid), array('id' => $log['id']));
211
+//            //增加会员余额
212
+//            m('member')->setCredit($log['openid'], 'credit2', $log['money'], array(0, $_W['shopset']['shop']['name'].'会员充值:alipayreturn:credit2:' . $log['money']));
213
+//            //充值积分
214
+//            m('member')->setRechargeCredit($log['openid'], $log['money']);
215
+//            //充值活动
216
+//            com_run('sale::setRechargeActivity', $log);
217
+//
218
+//            //优惠券
219
+//            com_run('coupon::useRechargeCoupon', $log);
220
+//
221
+//            //模板消息
222
+//            m('notice')->sendMemberLogMessage($log['id']);
223
+//
224
+//            //充值打印小票
225
+//            $member =m('member')->getMember($log['openid']);
226
+//            $params=array(
227
+//                'nickname'=>empty($member['nickname'])?'未更新':$member['nickname'],
228
+//                'price'=>$log['money'],
229
+//                'paytype'=>'支付宝支付',
230
+//                'paytime'=>date("Y-m-d H:i:s",time()),
231
+//            );
232
+//            com_run('printer::sendRechargeMessage',$params);
233
+//        }
234
+
235
+        if(is_h5app()){
236
+            $url = mobileUrl('member', null, true);
237
+            die("<script>top.window.location.href='{$url}'</script>");
238
+        }else{
239
+            if ($fromwechat){
240
+                $this->message(array("message"=>"请返回微信查看支付状态", "title"=>"支付成功!", "buttondisplay"=>false), null, 'success');
241
+            }else{
242
+                $this->message(array("message"=>"请返回商城查看支付状态", "title"=>"支付成功!"), mobileUrl('member'), 'success');
243
+            }
244
+        }
245
+    }
246
+
247
+    protected function str($str){
248
+        $str = str_replace('"', '', $str);
249
+        $str = str_replace("'", '', $str);
250
+        return $str;
251
+    }
252
+
253
+}

+ 298 - 0
addons/ewei_shopv2/core/mobile/order/refund.php Parādīt failu

@@ -0,0 +1,298 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+    exit('Access Denied');
4
+}
5
+
6
+class Refund_EweiShopV2Page extends MobileLoginPage {
7
+
8
+    protected function globalData() {
9
+        global $_W, $_GPC;
10
+        $uniacid = $_W['uniacid'];
11
+        $openid = $_W['openid'];
12
+        $orderid = intval($_GPC['id']);
13
+
14
+        $order = pdo_fetch("select id,status,price,refundid,goodsprice,dispatchprice,deductprice,deductcredit2,finishtime,isverify,`virtual`,refundstate,merchid,random_code,iscycelbuy from " . tablename('ewei_shop_order') . ' where id=:id and uniacid=:uniacid and openid=:openid limit 1'
15
+            , array(':id' => $orderid, ':uniacid' => $uniacid, ':openid' => $openid));
16
+        $orderprice = $order['price'];
17
+
18
+        if( $order['iscycelbuy'] == 1 ){
19
+            //查询分期订单下面是否存在有开始的周期商品
20
+            $order_goods = pdo_fetch( "select * from ".tablename( 'ewei_shop_cycelbuy_periods' )."where orderid = {$order['id']} and status != 0" );
21
+            if( !empty($order_goods) ){
22
+                show_json( 0 , '订单已经开始,无法进行退款' );
23
+            }
24
+        }
25
+
26
+
27
+        if (empty($order)) {
28
+            if (!$_W['isajax']) {
29
+                header('location: ' . mobileUrl('order'));
30
+                exit;
31
+            } else {
32
+                show_json(0, '订单未找到');
33
+            }
34
+        }
35
+
36
+        $_err = '';
37
+        if ($order['status'] == 0) {
38
+            $_err = '订单未付款,不能申请退款!';
39
+        } else {
40
+            if ($order['status'] == 3) {
41
+                if (!empty($order['virtual']) || $order['isverify'] == 1) {
42
+                    $_err = '此订单不允许退款!';
43
+                } else {
44
+                    if ($order['refundstate'] == 0) {
45
+                        //申请退款
46
+                        $tradeset = m('common')->getSysset('trade');
47
+                        $refunddays = intval($tradeset['refunddays']);
48
+                        if ($refunddays > 0) {
49
+                            $days = intval((time() - $order['finishtime']) / 3600 / 24);
50
+                            if ($days > $refunddays) {
51
+                                $_err = '订单完成已超过 ' . $refunddays . ' 天, 无法发起退款申请!';
52
+                            }
53
+                        } else {
54
+                            $_err = '订单完成, 无法申请退款!';
55
+                        }
56
+                    }
57
+                }
58
+            }
59
+        }
60
+
61
+        if (!empty($_err)) {
62
+            if ($_W['isajax']) {
63
+                show_json(0, $_err);
64
+            } else {
65
+                $this->message($_err, '', 'error');
66
+            }
67
+        }
68
+
69
+
70
+        //订单不能退货商品
71
+
72
+        /*********************************************************************/
73
+        $order['cannotrefund'] = false;
74
+
75
+        if($order['status']==2){
76
+            $goods = pdo_fetchall("select og.goodsid, og.price, og.total, og.optionname, g.cannotrefund, g.thumb, g.title,g.isfullback from".tablename("ewei_shop_order_goods") ." og left join ".tablename("ewei_shop_goods")." g on g.id=og.goodsid where og.orderid=".$order['id']);
77
+            if(!empty($goods)){
78
+                foreach ($goods as $g){
79
+                    if($g['cannotrefund']==1){
80
+                        $order['cannotrefund'] = true;
81
+                        break;
82
+                    }
83
+                }
84
+            }
85
+        }
86
+        if($order['cannotrefund']){
87
+            $this->message("此订单不可退换货");
88
+        }
89
+
90
+        //是否全返商品,并检测是否允许退款
91
+        $fullback_log = pdo_fetch("select * from ".tablename('ewei_shop_fullback_log')." where orderid = ".$orderid." and uniacid = ".$uniacid." ");
92
+        if($fullback_log){
93
+            $fullbackgoods = pdo_fetch("select refund from ".tablename('ewei_shop_fullback_goods')." where goodsid = ".$fullback_log['goodsid']." and uniacid = ".$uniacid." ");
94
+            if($fullback_log['fullbackday']>0){
95
+                if($fullback_log['fullbackday']<$fullback_log['day']){
96
+                    $order['price'] = $order['price'] - $fullback_log['priceevery'] * $fullback_log['fullbackday'];
97
+                }else{
98
+                    $order['price'] = $order['price'] - $fullback_log['price'];
99
+                }
100
+            }
101
+        }
102
+
103
+
104
+        //应该退的钱 在线支付的+积分抵扣的+余额抵扣的(运费包含在在线支付或余额里)
105
+        $order['refundprice'] = $order['price'] + $order['deductcredit2'];
106
+        if ($order['status'] >= 2) {
107
+            //如果发货,扣除运费
108
+            $order['refundprice']-= $order['dispatchprice'];
109
+        }
110
+        $order['refundprice'] = round($order['refundprice'],2);
111
+
112
+        return array(
113
+            'uniacid' => $uniacid,
114
+            'openid' => $_W['openid'],
115
+            'orderid' => $orderid,
116
+            'order' => $order,
117
+            'refundid' => $order['refundid'],
118
+            'fullback_log'=>$fullback_log,
119
+            'fullbackgoods'=>$fullbackgoods,
120
+            'orderprice'=>$orderprice
121
+        );
122
+    }
123
+
124
+    function main() {
125
+
126
+        global $_W, $_GPC;
127
+        extract($this->globalData());
128
+        if($order['status'] == 2 && $order['price'] == $order['dispatchprice']) {
129
+            $canreturns = 1;
130
+        }
131
+        if ( $order['status'] == '-1')
132
+            $this->message('请不要重复提交!','','error');
133
+        $refund = false;
134
+        $imgnum = 0;
135
+        if ($order['refundstate'] > 0) {
136
+            if (!empty($refundid)) {
137
+                $refund = pdo_fetch("select * from " . tablename('ewei_shop_order_refund') . ' where id=:id and uniacid=:uniacid and orderid=:orderid limit 1'
138
+                    , array(':id' => $refundid, ':uniacid' => $uniacid, ':orderid' => $orderid));
139
+                if (!empty($refund['refundaddress'])) {
140
+                    $refund['refundaddress'] = iunserializer($refund['refundaddress']);
141
+                }
142
+            }
143
+            if (!empty($refund['imgs'])) {
144
+                $refund['imgs'] = iunserializer($refund['imgs']);
145
+            }
146
+        }
147
+
148
+        if (empty($refund)) {
149
+            $show_price =round( $order['refundprice'],2);
150
+        } else {
151
+            $show_price = round($refund['applyprice'],2);
152
+        }
153
+
154
+        $express_list = m('express')->getExpressList();
155
+
156
+        $trade = m('common')->getSysset('trade', $_W['uniacid']);
157
+        include $this->template();
158
+    }
159
+
160
+    //提交
161
+    function submit() {
162
+
163
+        global $_W, $_GPC;
164
+        extract($this->globalData());
165
+        if ( $order['status'] == '-1')
166
+            show_json(0, '订单已经处理完毕!');
167
+        $price = trim($_GPC['price']);
168
+        $rtype = intval($_GPC['rtype']);
169
+        if ($rtype != 2) {
170
+            if (empty($price) && $order['deductprice'] == 0) {
171
+                show_json(0, '退款金额不能为0元');
172
+            }
173
+            if ($price > $order['refundprice']) {
174
+                show_json(0, '退款金额不能超过' . $order['refundprice'] . '元');
175
+            }
176
+        }
177
+        //全返退款,退款退货
178
+        if(($rtype==0 || $rtype==1) && $order['status']>=3){
179
+
180
+            // if(($fullback_log['price']>=$orderprice || $fullbackgoods['refund'] == 0) && $fullback_log){
181
+            //     show_json(0, "此订单不可退款");
182
+            // }
183
+            //全返管理停止
184
+            if($fullback_log){
185
+                m('order')->fullbackstop($orderid);
186
+            }
187
+        }
188
+        $refund = array(
189
+            'uniacid' => $uniacid,
190
+            'merchid' => $order['merchid'],
191
+            'applyprice' => $price,
192
+            'rtype' => $rtype,
193
+            'reason' => trim($_GPC['reason']),
194
+            'content' => trim($_GPC['content']),
195
+            'imgs' => iserializer($_GPC['images'])
196
+        );
197
+
198
+        if ($refund['rtype'] == 2) {
199
+            $refundstate = 2;
200
+        } else {
201
+            $refundstate = 1;
202
+        }
203
+        if ($order['refundstate'] == 0) {
204
+            //新建一条退款申请
205
+            $refund['createtime'] = time();
206
+            $refund['orderid'] = $orderid;
207
+            $refund['orderprice'] = $order['refundprice'];
208
+            $refund['refundno'] = m('common')->createNO('order_refund', 'refundno', 'SR');
209
+            pdo_insert('ewei_shop_order_refund', $refund);
210
+            $refundid = pdo_insertid();
211
+            pdo_update('ewei_shop_order', array('refundid' => $refundid, 'refundstate' => $refundstate), array('id' => $orderid, 'uniacid' => $uniacid));
212
+        } else {
213
+            //修改退款申请
214
+            pdo_update('ewei_shop_order', array('refundstate' => $refundstate), array('id' => $orderid, 'uniacid' => $uniacid));
215
+            pdo_update('ewei_shop_order_refund', $refund, array('id' => $refundid, 'uniacid' => $uniacid));
216
+        }
217
+        //模板消息
218
+        m('notice')->sendOrderMessage($orderid, true);
219
+        show_json(1);
220
+    }
221
+
222
+    //取消
223
+    function cancel() {
224
+
225
+        global $_W, $_GPC;
226
+        extract($this->globalData());
227
+        $change_refund = array();
228
+        $change_refund['status'] = -2;
229
+        $change_refund['refundtime'] = time();
230
+        pdo_update('ewei_shop_order_refund', $change_refund, array('id' => $refundid, 'uniacid' => $uniacid));
231
+        pdo_update('ewei_shop_order', array('refundstate' => 0), array('id' => $orderid, 'uniacid' => $uniacid));
232
+        show_json(1);
233
+    }
234
+
235
+    //填写快递单号
236
+    function express() {
237
+
238
+        global $_W, $_GPC;
239
+        extract($this->globalData());
240
+        if (empty($refundid)) {
241
+            show_json(0, '参数错误!');
242
+        }
243
+        if (empty($_GPC['expresssn'])) {
244
+            show_json(0, '请填写快递单号');
245
+        }
246
+        $refund = array(
247
+            'status'=>4,
248
+            'express'=>trim($_GPC['express']),
249
+            'expresscom'=>trim($_GPC['expresscom']),
250
+            'expresssn'=>trim($_GPC['expresssn']),
251
+            'sendtime'=>time()
252
+        );
253
+        pdo_update('ewei_shop_order_refund', $refund, array('id' => $refundid, 'uniacid' => $uniacid));
254
+        show_json(1);
255
+    }
256
+
257
+    //收到换货商品
258
+    function receive(){
259
+
260
+        global $_W, $_GPC;
261
+        extract($this->globalData());
262
+        $refundid = intval($_GPC['refundid']);
263
+        $refund =  pdo_fetch("select * from " . tablename('ewei_shop_order_refund') . ' where id=:id and uniacid=:uniacid and orderid=:orderid limit 1'
264
+            , array(':id' => $refundid, ':uniacid' => $uniacid, ':orderid' => $orderid));
265
+        if (empty($refund)) {
266
+            show_json(0, '换货申请未找到!');
267
+        }
268
+
269
+        $time = time();
270
+        $refund_data = array();
271
+        $refund_data['status'] = 1;
272
+        $refund_data['refundtime'] = $time;
273
+        pdo_update('ewei_shop_order_refund', $refund_data, array('id'=>$refundid, 'uniacid' => $uniacid));
274
+
275
+        $order_data = array();
276
+        $order_data['refundstate'] = 0;
277
+        $order_data['status'] = 3;
278
+        $order_data['refundtime'] = $time;
279
+        $order_data['finishtime'] = $time;
280
+        pdo_update('ewei_shop_order', $order_data, array('id'=>$orderid, 'uniacid' => $uniacid));
281
+        show_json(1);
282
+
283
+    }
284
+
285
+    //查询商家重新发货快递
286
+    function refundexpress() {
287
+
288
+        global $_W, $_GPC;
289
+        extract($this->globalData());
290
+
291
+        $express = trim($_GPC['express']);
292
+        $expresssn = trim($_GPC['expresssn']);
293
+        $expresscom = trim($_GPC['expresscom']);
294
+        $expresslist = m('util')->getExpressList($express, $expresssn);
295
+
296
+        include $this->template('order/refundexpress');
297
+    }
298
+}

+ 335 - 0
addons/ewei_shopv2/core/mobile/order/single_refund.php Parādīt failu

@@ -0,0 +1,335 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+    exit('Access Denied');
4
+}
5
+
6
+class Single_Refund_EweiShopV2Page extends MobileLoginPage {
7
+
8
+    protected function globalData() {
9
+        global $_W, $_GPC;
10
+        $order_goodsid = intval($_GPC['id']);
11
+        $openid = $_W['openid'];
12
+        $uniacid = $_W['uniacid'];
13
+
14
+        //订单商品
15
+        $order = pdo_fetch('select o.id,o.price,o.couponprice,o.iscycelbuy,o.status,o.virtual,o.isverify,o.refundstate,o.finishtime,o.deductprice,o.deductcredit2,o.dispatchprice,o.deductenough,o.merchdeductenough,g.cannotrefund,og.single_refundid,og.single_refundstate,og.single_refundtime,og.realprice as og_realprice,o.grprice,og.consume,o.ispackage,og.sendtime from ' . tablename('ewei_shop_order') .' o '
16
+            . ' left join ' . tablename('ewei_shop_order_goods') . ' og on og.orderid=o.id'
17
+            . ' left join ' . tablename('ewei_shop_goods') . ' g on g.id=og.goodsid'
18
+            . ' where og.id=:ogid and o.openid=:openid and o.uniacid=:uniacid'
19
+            , array(':ogid' => $order_goodsid,':openid' => $openid,':uniacid' => $uniacid));
20
+
21
+//        dump(iunserializer($order['consume']));die;
22
+
23
+        if (empty($order)) {
24
+            if (!$_W['isajax']) {
25
+                header('location: ' . mobileUrl('order'));
26
+                exit;
27
+            } else {
28
+                show_json(0, '订单未找到');
29
+            }
30
+        }
31
+
32
+        $_err = '';
33
+        if($order['iscycelbuy'] == 1 ){
34
+            //查询分期订单下面是否存在有开始的周期商品
35
+            $order_goods = pdo_fetch( "select * from ".tablename( 'ewei_shop_cycelbuy_periods' )."where orderid = {$order['id']} and status != 0" );
36
+            if( !empty($order_goods) ){
37
+                $_err='订单已经开始,无法进行单商品退款';
38
+            }
39
+        }
40
+
41
+        if(!empty($order['ispackage'])){
42
+            $_err = '套餐订单,无法进行单品维权!';
43
+        }
44
+
45
+        //代付
46
+        $ispeerpay = m('order')->checkpeerpay($order['id']);//检查是否是代付订单
47
+        if(!empty($ispeerpay)){
48
+            $_err = '代付订单,无法进行单品维权!';
49
+        }
50
+
51
+        //存在全返,无法进行单商品退款
52
+        $fullback_goods_count = pdo_fetchcolumn('select count(og.id) from ' . tablename('ewei_shop_order_goods') .' og '
53
+            . ' left join ' . tablename('ewei_shop_goods') . ' g on g.id=og.goodsid'
54
+            . ' where og.orderid=:orderid and g.isfullback>0 and og.uniacid=:uniacid'
55
+            , array(':orderid' => $order['id'], ':uniacid' => $uniacid));
56
+        if(!empty($fullback_goods_count)){
57
+            $_err = '全返订单,无法进行单商品退款';
58
+        }
59
+
60
+        if ($order['status'] == 0) {
61
+            $_err = '订单未付款,不能申请退款!';
62
+        } elseif($order['status']==2 && !empty($order['cannotrefund'])) {
63
+            $_err = '此商品不可退换货!';
64
+        }elseif($order['status'] == 3) {
65
+            if (!empty($order['virtual']) || $order['isverify'] == 1) {
66
+                $_err = '此订单不允许退款!';
67
+            } else {
68
+                //申请退款
69
+                $tradeset = m('common')->getSysset('trade');
70
+                $refunddays = intval($tradeset['refunddays']);
71
+                if ($refunddays > 0) {
72
+                    $days = intval((time() - $order['finishtime']) / 3600 / 24);
73
+                    if ($days > $refunddays) {
74
+                        $_err = '订单完成已超过 ' . $refunddays . ' 天, 无法发起退款申请!';
75
+                    }
76
+                } else {
77
+                    $_err = '订单完成, 无法申请退款!';
78
+                }
79
+            }
80
+        }
81
+
82
+        if (!empty($_err)) {
83
+            if ($_W['isajax']) {
84
+                show_json(0, $_err);
85
+            } else {
86
+                $this->message($_err, '', 'error');
87
+            }
88
+        }
89
+
90
+        //订单所有商品 关联 退款表
91
+        $order_goods = pdo_fetchall('select og.id,og.single_refundid,og.single_refundstate,r.applyprice from ' . tablename('ewei_shop_order_goods') .' og '
92
+            . ' left join ' . tablename('ewei_shop_order_single_refund') . ' r on r.id=og.single_refundid'
93
+            . ' where og.orderid=:orderid and og.uniacid=:uniacid'
94
+            , array(':orderid' => $order['id'], ':uniacid' => $uniacid));
95
+
96
+        $is_last=true;//是否是订单最后一个退款商品
97
+        $refund_price=0;//订单商品退款总额
98
+        foreach ($order_goods as $og){
99
+
100
+            //过滤当前申请的ordergoods
101
+            if(intval($og['id']) != $order_goodsid){
102
+                if(empty($og['single_refundid'])){
103
+                    $is_last=false;
104
+                    break;
105
+                }
106
+
107
+                //其他商品退款总额
108
+                $refund_price+=$og['applyprice'];
109
+            }
110
+        }
111
+
112
+        if($is_last){
113
+            //应退金额=订单实际付款金额-其他商品退款总额
114
+            $order['single_refundprice']=$order['price']-$refund_price;
115
+            if ($order['status'] > 2) {
116
+                //如果已经发货,退款金额减去运费
117
+                $order['single_refundprice'] -= $order['dispatchprice'];
118
+            }
119
+        }else{
120
+            //订单优惠金额(不包含商品促销或会员折扣) = 积分抵扣金额+余额抵扣金额+商城满减金额+多商户满减金额+优惠券金额
121
+            $order_discount=$order['deductprice']+$order['deductcredit2']+$order['deductenough']+$order['merchdeductenough']+$order['couponprice'];
122
+
123
+            //商品优惠金额 = 订单优惠金额 x ( 商品实际付款金额(折扣后的商品价格,不包含运费) / 订单商品实际总价(折扣后的订单总价,不包含运费) )
124
+            $goods_discount =round($order_discount*($order['og_realprice']/$order['grprice']),2);
125
+
126
+            //应退金额=商品实际付款金额(折扣后的商品价格,不包含运费)-商品优惠金额
127
+            $order['single_refundprice']=$order['og_realprice']-$goods_discount;
128
+        }
129
+
130
+        if($order['single_refundprice']<=0){
131
+            $order['single_refundprice']=0;
132
+        }
133
+
134
+        return array(
135
+            'uniacid' => $uniacid,
136
+            'openid' => $_W['openid'],
137
+            'order_goodsid' => $order_goodsid,
138
+            'order' => $order,
139
+            'single_refundid' => $order['single_refundid'],
140
+
141
+        );
142
+    }
143
+
144
+    function main() {
145
+
146
+        global $_W, $_GPC;
147
+        extract($this->globalData());
148
+        if($order['status'] == 2 && $order['price'] == $order['dispatchprice']) {
149
+            $canreturns = 1;
150
+        }
151
+//        if ( $order['status'] == '-1'){
152
+//            $this->message('请不要重复提交!','','error');
153
+//        }
154
+        $refund = false;
155
+
156
+        if (!empty($single_refundid)) {
157
+            $refund = pdo_fetch("select * from " . tablename('ewei_shop_order_single_refund') . ' where id=:id and ordergoodsid=:ordergoodsid and uniacid=:uniacid limit 1'
158
+                , array(':id' => $single_refundid,':ordergoodsid' => $order_goodsid,':uniacid' => $uniacid));
159
+            if (!empty($refund['refundaddress'])) {
160
+                $refund['refundaddress'] = iunserializer($refund['refundaddress']);
161
+            }
162
+        }
163
+        if (!empty($refund['imgs'])) {
164
+            $refund['imgs'] = iunserializer($refund['imgs']);
165
+        }
166
+
167
+        $express_list = m('express')->getExpressList();
168
+        $trade = m('common')->getSysset('trade', $_W['uniacid']);
169
+
170
+        include $this->template();
171
+    }
172
+
173
+    //提交
174
+    function submit() {
175
+
176
+        global $_W, $_GPC;
177
+        extract($this->globalData());
178
+        if ($order['single_refundstate'] == '9'){
179
+            show_json(0, '商品维权已经处理完毕!');
180
+        }
181
+        $price = floatval($_GPC['price']);
182
+        $rtype = intval($_GPC['rtype']);
183
+        if ($rtype != 2) {
184
+            if (empty($price) && $order['deductprice'] == 0) {
185
+                show_json(0, '退款金额不能为0元');
186
+            }
187
+
188
+            if (bccomp($price,$order['single_refundprice'],2)==1 ) {
189
+                show_json(0, '退款金额不能超过' . $order['single_refundprice'] . '元');
190
+            }
191
+        }
192
+
193
+        $refund = array(
194
+            'uniacid' => $uniacid,
195
+            'merchid' => $order['merchid'],
196
+            'applyprice' => $price,
197
+            'rtype' => $rtype,
198
+            'reason' => trim($_GPC['reason']),
199
+            'content' => trim($_GPC['content']),
200
+            'imgs' => iserializer($_GPC['images'])
201
+        );
202
+
203
+        if ($refund['rtype'] == 2) {
204
+            $refundstate = 2;
205
+        } else {
206
+            $refundstate = 1;
207
+        }
208
+        if ($order['single_refundstate'] == 0) {
209
+            //新建一条退款申请
210
+            $refund['createtime'] = time();
211
+            $refund['orderid'] = $order['id'];
212
+            $refund['ordergoodsid'] = $order_goodsid;
213
+            $refund['ordergoodsrealprice'] = $order['og_realprice'];//商品实际付款金额(折扣后的商品价格,不包含运费)
214
+            $refund['refundno'] = m('common')->createNO('order_refund', 'refundno', 'SR');
215
+            pdo_insert('ewei_shop_order_single_refund', $refund);
216
+            $single_refundid = pdo_insertid();
217
+            pdo_update('ewei_shop_order_goods', array('single_refundid' => $single_refundid, 'single_refundstate' => $refundstate), array('id' => $order_goodsid, 'uniacid' => $uniacid));
218
+        } else {
219
+            //修改退款申请
220
+            $refund['status']=0;
221
+            pdo_update('ewei_shop_order_goods', array('single_refundstate' => $refundstate), array('id' => $order_goodsid, 'uniacid' => $uniacid));
222
+            pdo_update('ewei_shop_order_single_refund', $refund, array('id' => $single_refundid, 'uniacid' => $uniacid));
223
+        }
224
+
225
+        pdo_update('ewei_shop_order', array('refundstate' => 3,'refundtime'=>0), array('id' => $order['id'], 'uniacid' => $uniacid));
226
+
227
+        //模板消息
228
+        m('notice')->sendOrderMessage($order['id'], true);
229
+        show_json(1);
230
+    }
231
+
232
+    //取消
233
+    function cancel() {
234
+
235
+        global $_W, $_GPC;
236
+        extract($this->globalData());
237
+        $change_refund = array();
238
+        $change_refund['status'] = -2;
239
+        $change_refund['refundtime'] = time();
240
+        pdo_update('ewei_shop_order_single_refund', $change_refund, array('id' => $single_refundid, 'uniacid' => $uniacid));
241
+        pdo_update('ewei_shop_order_goods', array('single_refundstate' => 0), array('id' => $order_goodsid, 'uniacid' => $uniacid));
242
+
243
+        $order_goods=pdo_fetchall("select single_refundid,single_refundstate,single_refundtime from ".tablename('ewei_shop_order_goods')." where orderid=:orderid",array(':orderid'=>$order['id']));
244
+        $refund_num=0;//退款过的订单商品数量
245
+        $apply_refund_num=0;//申请维权中的订单商品数量
246
+        foreach ($order_goods as $og){
247
+            if($og['single_refundtime']>0){
248
+                $refund_num++;
249
+            }
250
+            if($og['single_refundstate']==1 || $og['single_refundstate']==2){
251
+                $apply_refund_num++;
252
+            }
253
+        }
254
+
255
+        if(empty($apply_refund_num) && !empty($refund_num)){
256
+            pdo_update('ewei_shop_order', array('refundtime'=>time()), array('id' => $order['id'], 'uniacid' => $uniacid));
257
+        }
258
+
259
+        if(empty($apply_refund_num) && empty($refund_num)){
260
+            pdo_update('ewei_shop_order', array('refundstate' => 0,'refundtime'=>0), array('id' => $order['id'], 'uniacid' => $uniacid));
261
+        }
262
+
263
+        show_json(1);
264
+    }
265
+
266
+    //填写快递单号
267
+    function express() {
268
+
269
+        global $_W, $_GPC;
270
+        extract($this->globalData());
271
+        if (empty($single_refundid)) {
272
+            show_json(0, '参数错误!');
273
+        }
274
+        if (empty($_GPC['expresssn'])) {
275
+            show_json(0, '请填写快递单号');
276
+        }
277
+        $refund = array(
278
+            'status'=>4,
279
+            'express'=>trim($_GPC['express']),
280
+            'expresscom'=>trim($_GPC['expresscom']),
281
+            'expresssn'=>trim($_GPC['expresssn']),
282
+            'sendtime'=>time()
283
+        );
284
+        pdo_update('ewei_shop_order_single_refund', $refund, array('id' => $single_refundid, 'uniacid' => $uniacid));
285
+        show_json(1);
286
+    }
287
+
288
+    //收到换货商品
289
+    function receive(){
290
+
291
+        global $_W, $_GPC;
292
+        extract($this->globalData());
293
+        $single_refundid = intval($_GPC['single_refundid']);
294
+        $refund =  pdo_fetch("select * from " . tablename('ewei_shop_order_single_refund') . ' where id=:id and ordergoodsid=:ordergoodsid and uniacid=:uniacid limit 1'
295
+            , array(':id' => $single_refundid,':ordergoodsid' => $order_goodsid,':uniacid' => $uniacid,));
296
+        if (empty($refund)) {
297
+            show_json(0, '换货申请未找到!');
298
+        }
299
+
300
+        $time = time();
301
+        $refund_data = array();
302
+        $refund_data['status'] = 1;
303
+        $refund_data['refundtime'] = $time;
304
+        pdo_update('ewei_shop_order_single_refund', $refund_data, array('id'=>$single_refundid, 'uniacid' => $uniacid));
305
+
306
+        $order_data = array();
307
+        $order_data['single_refundstate'] = 9;
308
+        pdo_update('ewei_shop_order_goods', $order_data, array('id'=>$order_goodsid, 'uniacid' => $uniacid));
309
+
310
+        //查询其它 订单商品 是否有正在维权中的
311
+        $is_single_refund=pdo_fetchcolumn('select count(id) from '.tablename('ewei_shop_order_goods').'where orderid=:orderid and (single_refundstate=1 or single_refundstate=2)',array(':orderid'=>$order['id']));
312
+
313
+        //如果其它 订单商品 没有正在维权中
314
+        if(empty($is_single_refund)){
315
+            //更新订单维权时间
316
+            pdo_update('ewei_shop_order', array('refundtime' => $time), array('id' => $order['id'], 'uniacid' => $uniacid));
317
+        }
318
+
319
+        show_json(1);
320
+    }
321
+
322
+    //查询商家重新发货快递
323
+    function refundexpress() {
324
+
325
+        global $_W, $_GPC;
326
+        extract($this->globalData());
327
+
328
+        $express = trim($_GPC['express']);
329
+        $expresssn = trim($_GPC['expresssn']);
330
+        $expresscom = trim($_GPC['expresscom']);
331
+        $expresslist = m('util')->getExpressList($express, $expresssn);
332
+
333
+        include $this->template('order/refundexpress');
334
+    }
335
+}

+ 426 - 0
addons/ewei_shopv2/core/mobile/sale/coupon/detail.php Parādīt failu

@@ -0,0 +1,426 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Detail_EweiShopV2Page extends MobilePage
7
+{
8
+	public function main()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$openid = $_W['openid'];
13
+		$id = intval($_GPC['id']);
14
+		$coupon = pdo_fetch('select * from ' . tablename('ewei_shop_coupon') . ' where id=:id and uniacid=:uniacid  limit 1', array(':id' => $id, ':uniacid' => $_W['uniacid']));
15
+
16
+		if (empty($coupon)) {
17
+			header('location: ' . mobileUrl('sale/coupon'));
18
+			exit();
19
+		}
20
+
21
+		$coupon = com('coupon')->setCoupon($coupon, time());
22
+		$title2 = '';
23
+		$title3 = '';
24
+
25
+		if ($coupon['coupontype'] == '0') {
26
+			if (0 < $coupon['enough']) {
27
+				$title2 = '满' . (double) $coupon['enough'] . '元可用';
28
+			}
29
+			else {
30
+				$title2 = '无金额门槛';
31
+			}
32
+		}
33
+		else {
34
+			if ($coupon['coupontype'] == '1') {
35
+				if (0 < $coupon['enough']) {
36
+					$title2 = '充值满' . (double) $coupon['enough'] . '元可用';
37
+				}
38
+				else {
39
+					$title2 = '无金额门槛';
40
+				}
41
+			}
42
+		}
43
+
44
+		if ($coupon['coupontype'] == '2') {
45
+			if (0 < $coupon['enough']) {
46
+				$title2 = '满' . (double) $coupon['enough'] . '元可用';
47
+			}
48
+			else {
49
+				$title2 = '无金额门槛';
50
+			}
51
+		}
52
+
53
+		if ($coupon['backtype'] == 0) {
54
+			if ($coupon['enough'] == '0') {
55
+				$coupon['color'] = 'orange';
56
+			}
57
+			else {
58
+				$coupon['color'] = 'blue';
59
+			}
60
+
61
+			$title3 = '<span class="subtitle nopadding">¥</span>' . (double) $coupon['deduct'];
62
+		}
63
+
64
+		if ($coupon['backtype'] == 1) {
65
+			$coupon['color'] = 'red ';
66
+			$title3 = (double) $coupon['discount'] . '折 ';
67
+		}
68
+
69
+		if ($coupon['backtype'] == 2) {
70
+			if ($coupon['coupontype'] == '0') {
71
+				$coupon['color'] = 'red ';
72
+			}
73
+			else {
74
+				$coupon['color'] = 'pink ';
75
+			}
76
+
77
+			if (!empty($coupon['backmoney']) && 0 < $coupon['backmoney']) {
78
+				$backmoneytext = $coupon['backmoney'] . '元余额 ';
79
+			}
80
+
81
+			if (!empty($coupon['backcredit']) && 0 < $coupon['backcredit']) {
82
+				$backcredittext = $coupon['backcredit'] . '积分 ';
83
+			}
84
+
85
+			if (!empty($coupon['backredpack']) && 0 < $coupon['backredpack']) {
86
+				$backredpacktext = $coupon['backredpack'] . '元红包';
87
+			}
88
+		}
89
+
90
+		$coupon['title2'] = $title2;
91
+		$coupon['title3'] = $title3;
92
+		$goods = array();
93
+		$category = array();
94
+
95
+		if ($coupon['limitgoodtype'] != 0) {
96
+			if (!empty($coupon['limitgoodids'])) {
97
+				$where = 'and id in(' . $coupon['limitgoodids'] . ')';
98
+			}
99
+
100
+			$goods = pdo_fetchall('select `title` from ' . tablename('ewei_shop_goods') . ' where uniacid=:uniacid ' . $where, array(':uniacid' => $_W['uniacid']), 'id');
101
+		}
102
+
103
+		if ($coupon['limitgoodcatetype'] != 0) {
104
+			if (!empty($coupon['limitgoodcateids'])) {
105
+				$where = 'and id in(' . $coupon['limitgoodcateids'] . ')';
106
+			}
107
+
108
+			$category = pdo_fetchall('select `name`  from ' . tablename('ewei_shop_category') . ' where uniacid=:uniacid   ' . $where, array(':uniacid' => $_W['uniacid']), 'id');
109
+		}
110
+
111
+		$limitmemberlevels = explode(',', $coupon['limitmemberlevels']);
112
+		$limitagentlevels = explode(',', $coupon['limitagentlevels']);
113
+		$limitpartnerlevels = explode(',', $coupon['limitpartnerlevels']);
114
+		$limitaagentlevels = explode(',', $coupon['limitaagentlevels']);
115
+		$hascommission = false;
116
+		$plugin_com = p('commission');
117
+
118
+		if ($plugin_com) {
119
+			$plugin_com_set = $plugin_com->getSet();
120
+			$leveltitle2 = $plugin_com_set['texts']['agent'];
121
+			$hascommission = !empty($plugin_com_set['level']);
122
+
123
+			if (in_array('0', $limitagentlevels)) {
124
+				$commissionname = empty($plugin_com_set['levelname']) ? '普通等级' : $plugin_com_set['levelname'];
125
+			}
126
+		}
127
+
128
+		$hasglobonus = false;
129
+		$plugin_globonus = p('globonus');
130
+
131
+		if ($plugin_globonus) {
132
+			$plugin_globonus_set = $plugin_globonus->getSet();
133
+			$leveltitle3 = $plugin_globonus_set['texts']['partner'];
134
+			$hasglobonus = !empty($plugin_globonus_set['open']);
135
+
136
+			if (in_array('0', $limitpartnerlevels)) {
137
+				$globonuname = empty($plugin_globonus_set['levelname']) ? '普通等级' : $plugin_globonus_set['levelname'];
138
+			}
139
+		}
140
+
141
+		$hasabonus = false;
142
+		$abonu = '';
143
+		$plugin_abonus = p('abonus');
144
+
145
+		if ($plugin_abonus) {
146
+			$plugin_abonus_set = $plugin_abonus->getSet();
147
+			$leveltitle4 = $plugin_abonus_set['texts']['aagent'];
148
+			$hasabonus = !empty($plugin_abonus_set['open']);
149
+
150
+			if (in_array('0', $limitaagentlevels)) {
151
+				$abonuname = empty($plugin_abonus_set['levelname']) ? '普通等级' : $plugin_abonus_set['levelname'];
152
+			}
153
+		}
154
+
155
+		$pass = false;
156
+
157
+		if ($coupon['islimitlevel'] == 1) {
158
+			$openid = trim($_W['openid']);
159
+			$member = m('member')->getMember($openid);
160
+			if (!empty($coupon['limitmemberlevels']) || $coupon['limitmemberlevels'] == '0') {
161
+				$shop = $_W['shopset']['shop'];
162
+
163
+				if (in_array('0', $limitmemberlevels)) {
164
+					$meblvname = empty($shop['levelname']) ? '普通等级' : $shop['levelname'];
165
+				}
166
+
167
+				$level1 = pdo_fetchall('select * from ' . tablename('ewei_shop_member_level') . ' where uniacid=:uniacid and  id in (' . $coupon['limitmemberlevels'] . ') ', array(':uniacid' => $_W['uniacid']));
168
+
169
+				if (in_array($member['level'], $limitmemberlevels)) {
170
+					$pass = true;
171
+				}
172
+			}
173
+
174
+			if ((!empty($coupon['limitagentlevels']) || $coupon['limitagentlevels'] == '0') && $hascommission) {
175
+				$level2 = pdo_fetchall('select * from ' . tablename('ewei_shop_commission_level') . ' where uniacid=:uniacid and id  in (' . $coupon['limitagentlevels'] . ') ', array(':uniacid' => $_W['uniacid']));
176
+				if ($member['isagent'] == '1' && $member['status'] == '1') {
177
+					if (in_array($member['agentlevel'], $limitagentlevels)) {
178
+						$pass = true;
179
+					}
180
+				}
181
+			}
182
+
183
+			if ((!empty($coupon['limitpartnerlevels']) || $coupon['limitpartnerlevels'] == '0') && $hasglobonus) {
184
+				$level3 = pdo_fetchall('select * from ' . tablename('ewei_shop_globonus_level') . ' where uniacid=:uniacid and  id in(' . $coupon['limitpartnerlevels'] . ') ', array(':uniacid' => $_W['uniacid']));
185
+				if ($member['ispartner'] == '1' && $member['partnerstatus'] == '1') {
186
+					if (in_array($member['partnerlevel'], $limitpartnerlevels)) {
187
+						$pass = true;
188
+					}
189
+				}
190
+			}
191
+
192
+			if ((!empty($coupon['limitaagentlevels']) || $coupon['limitaagentlevels'] == '0') && $hasabonus) {
193
+				$level4 = pdo_fetchall('select * from ' . tablename('ewei_shop_abonus_level') . ' where uniacid=:uniacid and  id in (' . $coupon['limitaagentlevels'] . ') ', array(':uniacid' => $_W['uniacid']));
194
+				if ($member['isaagent'] == '1' && $member['aagentstatus'] == '1') {
195
+					if (in_array($member['aagentlevel'], $limitaagentlevels)) {
196
+						$pass = true;
197
+					}
198
+				}
199
+			}
200
+		}
201
+		else {
202
+			$pass = true;
203
+		}
204
+
205
+		$set = m('common')->getPluginset('coupon');
206
+
207
+		if (is_h5app()) {
208
+			$sec = m('common')->getSec();
209
+			$sec = iunserializer($sec['sec']);
210
+			$shopset = m('common')->getSysset();
211
+			$payinfo = array('wechat' => !empty($sec['app_wechat']['merchname']) && !empty($shopset['pay']['app_wechat']) && !empty($sec['app_wechat']['appid']) && !empty($sec['app_wechat']['appsecret']) && !empty($sec['app_wechat']['merchid']) && !empty($sec['app_wechat']['apikey']) ? true : false, 'alipay' => false, 'mcname' => $sec['app_wechat']['merchname'], 'logno' => NULL, 'money' => NULL, 'attach' => $_W['uniacid'] . ':4', 'type' => 4);
212
+		}
213
+
214
+		list(, $payment) = m('common')->public_build();
215
+
216
+		if (!empty($payment['is_new'])) {
217
+			if ($payment['type'] == 2 || $payment['type'] == 3) {
218
+				if (!empty($payment['sub_appsecret'])) {
219
+					m('member')->wxuser($payment['sub_appid'], $payment['sub_appsecret']);
220
+				}
221
+			}
222
+		}
223
+
224
+		include $this->template();
225
+	}
226
+
227
+	public function pay($a = array(), $b = array())
228
+	{
229
+		global $_W;
230
+		global $_GPC;
231
+		$openid = $_W['openid'];
232
+		$id = intval($_GPC['id']);
233
+		$coupon = pdo_fetch('select * from ' . tablename('ewei_shop_coupon') . ' where id=:id and uniacid=:uniacid  limit 1', array(':id' => $id, ':uniacid' => $_W['uniacid']));
234
+		$coupon = com('coupon')->setCoupon($coupon, time());
235
+
236
+		if (empty($coupon['gettype'])) {
237
+			show_json(-1, '无法' . $coupon['gettypestr']);
238
+		}
239
+
240
+		if ($coupon['total'] != -1) {
241
+			if ($coupon['total'] <= 0) {
242
+				show_json(-1, '优惠券数量不足');
243
+			}
244
+		}
245
+
246
+		if (!$coupon['canget']) {
247
+			show_json(-1, '您已超出' . $coupon['gettypestr'] . '次数限制');
248
+		}
249
+
250
+		if (0 < $coupon['credit']) {
251
+			$credit = m('member')->getCredit($openid, 'credit1');
252
+
253
+			if ($credit < intval($coupon['credit'])) {
254
+				show_json(-1, '您的积分不足,无法' . $coupon['gettypestr'] . '!');
255
+			}
256
+		}
257
+
258
+		$needpay = false;
259
+
260
+		if (0 < $coupon['money']) {
261
+			pdo_delete('ewei_shop_coupon_log', array('couponid' => $id, 'openid' => $openid, 'status' => 0, 'paystatus' => 0));
262
+			$needpay = true;
263
+			$lastlog = pdo_fetch('select * from ' . tablename('ewei_shop_coupon_log') . ' where couponid=:couponid and openid=:openid  and status=0 and paystatus=1 and uniacid=:uniacid limit 1', array(':couponid' => $id, ':openid' => $openid, ':uniacid' => $_W['uniacid']));
264
+
265
+			if (!empty($lastlog)) {
266
+				show_json(1, array('logid' => $lastlog['id']));
267
+			}
268
+		}
269
+		else {
270
+			pdo_delete('ewei_shop_coupon_log', array('couponid' => $id, 'openid' => $openid, 'status' => 0));
271
+		}
272
+
273
+		$logno = m('common')->createNO('coupon_log', 'logno', 'CC');
274
+		$log = array('uniacid' => $_W['uniacid'], 'merchid' => $coupon['merchid'], 'openid' => $openid, 'logno' => $logno, 'couponid' => $id, 'status' => 0, 'paystatus' => 0 < $coupon['money'] ? 0 : -1, 'creditstatus' => 0 < $coupon['credit'] ? 0 : -1, 'createtime' => time(), 'getfrom' => 1);
275
+		pdo_insert('ewei_shop_coupon_log', $log);
276
+		$logid = pdo_insertid();
277
+
278
+		if ($needpay) {
279
+			$useweixin = true;
280
+
281
+			if (!empty($coupon['usecredit2'])) {
282
+				$money = m('member')->getCredit($openid, 'credit2');
283
+
284
+				if ($coupon['money'] <= $money) {
285
+					$useweixin = false;
286
+				}
287
+			}
288
+
289
+			pdo_update('ewei_shop_coupon_log', array('paytype' => $useweixin ? 1 : 0), array('id' => $logid));
290
+			$set = m('common')->getSysset();
291
+			$sec = m('common')->getSec();
292
+			$sec = iunserializer($sec['sec']);
293
+			if ($useweixin && is_h5app()) {
294
+				if (empty($sec['app_wechat']['merchname']) || empty($set['pay']['app_wechat']) || empty($sec['app_wechat']['appid']) || empty($sec['app_wechat']['appsecret']) || empty($sec['app_wechat']['merchid']) || empty($sec['app_wechat']['apikey']) || empty($coupon['money'])) {
295
+					$useweixin = false;
296
+				}
297
+			}
298
+
299
+			if ($useweixin) {
300
+				if (is_h5app()) {
301
+					show_json(1, array('needpay' => true, 'logid' => $logid, 'logno' => $logno, 'money' => $coupon['money']));
302
+				}
303
+
304
+				$set['pay']['weixin'] = !empty($set['pay']['weixin_sub']) ? 1 : $set['pay']['weixin'];
305
+				$set['pay']['weixin_jie'] = !empty($set['pay']['weixin_jie_sub']) ? 1 : $set['pay']['weixin_jie'];
306
+
307
+				if (!is_weixin()) {
308
+					show_json(-1, '非微信环境!');
309
+				}
310
+
311
+				if (empty($set['pay']['weixin']) && empty($set['pay']['weixin_jie'])) {
312
+					show_json(0, '未开启微信支付!');
313
+				}
314
+
315
+				$wechat = array('success' => false);
316
+				$jie = intval($_GPC['jie']);
317
+				$params = array();
318
+				$params['tid'] = $log['logno'];
319
+				$params['user'] = $openid;
320
+				$params['fee'] = $coupon['money'];
321
+				$params['title'] = $set['shop']['name'] . '优惠券领取单号:' . $log['logno'];
322
+				if (isset($set['pay']) && $set['pay']['weixin'] == 1 && $jie !== 1) {
323
+					load()->model('payment');
324
+					$setting = uni_setting($_W['uniacid'], array('payment'));
325
+					$options = array();
326
+
327
+					if (is_array($setting['payment'])) {
328
+						$options = $setting['payment']['wechat'];
329
+						$options['appid'] = $_W['account']['key'];
330
+						$options['secret'] = $_W['account']['secret'];
331
+					}
332
+
333
+					$wechat = m('common')->wechat_build($params, $options, 4);
334
+
335
+					if (!is_error($wechat)) {
336
+						$wechat['success'] = true;
337
+
338
+						if (!empty($wechat['code_url'])) {
339
+							$wechat['weixin_jie'] = true;
340
+						}
341
+						else {
342
+							$wechat['weixin'] = true;
343
+						}
344
+					}
345
+				}
346
+
347
+				if (isset($set['pay']) && $set['pay']['weixin_jie'] == 1 && !$wechat['success'] || $jie === 1) {
348
+					$params['tid'] = $params['tid'] . '_borrow';
349
+					$options = array();
350
+					$options['appid'] = $sec['appid'];
351
+					$options['mchid'] = $sec['mchid'];
352
+					$options['apikey'] = $sec['apikey'];
353
+					if (!empty($set['pay']['weixin_jie_sub']) && !empty($sec['sub_secret_jie_sub'])) {
354
+						$wxuser = m('member')->wxuser($sec['sub_appid_jie_sub'], $sec['sub_secret_jie_sub']);
355
+						$params['openid'] = $wxuser['openid'];
356
+					}
357
+					else {
358
+						if (!empty($sec['secret'])) {
359
+							$wxuser = m('member')->wxuser($sec['appid'], $sec['secret']);
360
+							$params['openid'] = $wxuser['openid'];
361
+						}
362
+					}
363
+
364
+					$wechat = m('common')->wechat_native_build($params, $options, 4);
365
+
366
+					if (!is_error($wechat)) {
367
+						$wechat['success'] = true;
368
+
369
+						if (!empty($params['openid'])) {
370
+							$wechat['weixin'] = true;
371
+						}
372
+						else {
373
+							$wechat['weixin_jie'] = true;
374
+						}
375
+					}
376
+				}
377
+
378
+				$wechat['jie'] = $jie;
379
+
380
+				if (!$wechat['success']) {
381
+					show_json(0, '微信支付参数错误!');
382
+				}
383
+
384
+				show_json(1, array('logid' => $logid, 'wechat' => $wechat));
385
+			}
386
+		}
387
+
388
+		show_json(1, array('logid' => $logid));
389
+	}
390
+
391
+	public function payresult($a = array())
392
+	{
393
+		global $_W;
394
+		global $_GPC;
395
+		$logid = intval($_GPC['logid']);
396
+		$log = pdo_fetch('select id,logno,status,paystatus,couponid from ' . tablename('ewei_shop_coupon_log') . ' where id=:id and uniacid=:uniacid limit 1', array(':id' => $logid, ':uniacid' => $_W['uniacid']));
397
+
398
+		if (empty($log)) {
399
+			show_json(-1, '订单未找到');
400
+		}
401
+
402
+		$coupon = com('coupon')->getCoupon($log['couponid']);
403
+		if (!empty($coupon['usecredit2']) || $coupon['money'] <= 0) {
404
+			$result = com('coupon')->payResult($log['logno']);
405
+
406
+			if (is_error($result)) {
407
+				show_json($result['errno'], $result['message']);
408
+			}
409
+		}
410
+		else {
411
+			if (empty($log['paystatus'])) {
412
+				show_json(0, '支付未成功!');
413
+			}
414
+		}
415
+
416
+		show_json(1, array('url' => $result['url'], 'dataid' => $result['dataid'], 'coupontype' => $result['coupontype']));
417
+	}
418
+
419
+	public function recommand()
420
+	{
421
+		$goods = m('goods')->getList(array('pagesize' => 4, 'isrecommand' => true, 'random' => true));
422
+		show_json(1, array('list' => $goods));
423
+	}
424
+}
425
+
426
+?>

+ 556 - 0
addons/ewei_shopv2/core/mobile/sale/coupon/index.php Parādīt failu

@@ -0,0 +1,556 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Index_EweiShopV2Page extends MobileLoginPage
7
+{
8
+	protected function merchData()
9
+	{
10
+		$merch_plugin = p('merch');
11
+		$merch_data = m('common')->getPluginset('merch');
12
+		if ($merch_plugin && $merch_data['is_openmerch']) {
13
+			$is_openmerch = 1;
14
+		}
15
+		else {
16
+			$is_openmerch = 0;
17
+		}
18
+
19
+		return array('is_openmerch' => $is_openmerch, 'merch_plugin' => $merch_plugin, 'merch_data' => $merch_data);
20
+	}
21
+
22
+	public function main()
23
+	{
24
+		global $_W;
25
+		global $_GPC;
26
+		$openid = $_W['openid'];
27
+		$cateid = trim($_GPC['catid']);
28
+		$timestamp = time();
29
+		$set = m('common')->getPluginset('coupon');
30
+
31
+		if (!empty($set['closecenter'])) {
32
+			header('location: ' . mobileUrl('member'));
33
+			exit();
34
+		}
35
+
36
+		$merchdata = $this->merchData();
37
+		extract($merchdata);
38
+		$advs = is_array($set['advs']) ? $set['advs'] : array();
39
+		$shop = m('common')->getSysset('shop');
40
+		$param = array();
41
+		$param[':uniacid'] = $_W['uniacid'];
42
+		$sql = 'select * from ' . tablename('ewei_shop_coupon_category') . ' where uniacid=:uniacid';
43
+
44
+		if ($is_openmerch == 0) {
45
+			$sql .= ' and merchid=0';
46
+		}
47
+		else {
48
+			if (!empty($_GPC['merchid'])) {
49
+				$sql .= ' and merchid=:merchid';
50
+				$param[':merchid'] = intval($_GPC['merchid']);
51
+			}
52
+		}
53
+
54
+		$sql .= ' and status=1 order by displayorder desc';
55
+		$category = pdo_fetchall($sql, $param);
56
+		include $this->template();
57
+	}
58
+
59
+	public function getcoupon($cateid)
60
+	{
61
+		global $_W;
62
+		$merchdata = $this->merchData();
63
+		extract($merchdata);
64
+		$time = time();
65
+		$param = array();
66
+		$param[':uniacid'] = $_W['uniacid'];
67
+		$sql = 'select id,timelimit,coupontype,timedays,timestart,timeend,couponname,enough,backtype,deduct,discount,backmoney,backcredit,backredpack,bgcolor,thumb,credit,money,getmax,merchid,total as t,tagtitle,settitlecolor,titlecolor  from ' . tablename('ewei_shop_coupon');
68
+		$sql .= ' where uniacid=:uniacid';
69
+
70
+		if ($is_openmerch == 0) {
71
+			$sql .= ' and merchid=0';
72
+		}
73
+		else {
74
+			if (!empty($_GPC['merchid'])) {
75
+				$sql .= ' and merchid=:merchid';
76
+				$param[':merchid'] = intval($_GPC['merchid']);
77
+			}
78
+		}
79
+
80
+		$plugin_com = p('commission');
81
+
82
+		if ($plugin_com) {
83
+			$plugin_com_set = $plugin_com->getSet();
84
+
85
+			if (empty($plugin_com_set['level'])) {
86
+				$sql .= ' and ( limitagentlevels = "" or  limitagentlevels is null )';
87
+			}
88
+		}
89
+		else {
90
+			$sql .= ' and ( limitagentlevels = "" or  limitagentlevels is null )';
91
+		}
92
+
93
+		$plugin_globonus = p('globonus');
94
+
95
+		if ($plugin_globonus) {
96
+			$plugin_globonus_set = $plugin_globonus->getSet();
97
+
98
+			if (empty($plugin_globonus_set['open'])) {
99
+				$sql .= ' and ( limitpartnerlevels = ""  or  limitpartnerlevels is null )';
100
+			}
101
+		}
102
+		else {
103
+			$sql .= ' and ( limitpartnerlevels = ""  or  limitpartnerlevels is null )';
104
+		}
105
+
106
+		$plugin_abonus = p('abonus');
107
+
108
+		if ($plugin_abonus) {
109
+			$plugin_abonus_set = $plugin_abonus->getSet();
110
+
111
+			if (empty($plugin_abonus_set['open'])) {
112
+				$sql .= ' and ( limitaagentlevels = "" or  limitaagentlevels is null )';
113
+			}
114
+		}
115
+		else {
116
+			$sql .= ' and ( limitaagentlevels = "" or  limitaagentlevels is null )';
117
+		}
118
+
119
+		$sql .= ' and gettype=1 and (total=-1 or total>0) and ( timelimit = 0 or  (timelimit=1 and timeend>unix_timestamp()))';
120
+
121
+		if (!empty($cateid)) {
122
+			$sql .= ' and catid=' . $cateid;
123
+		}
124
+
125
+		$sql .= ' order by displayorder desc, id desc ';
126
+		$coupons = set_medias(pdo_fetchall($sql, $param), 'thumb');
127
+
128
+		if (empty($coupons)) {
129
+			$coupons = array();
130
+		}
131
+
132
+		foreach ($coupons as $i => &$row) {
133
+			$row = com('coupon')->setCoupon($row, $time);
134
+			$last = com('coupon')->get_last_count($row['id']);
135
+			$row['contype'] = 2;
136
+
137
+			if ($row['t'] != -1) {
138
+				if ($last <= 0) {
139
+					$row['last'] = 0;
140
+					$row['isdisa'] = '1';
141
+				}
142
+				else {
143
+					$totle = $row['t'];
144
+					$row['last'] = $last;
145
+					$row['lastratio'] = intval($last / $totle * 100);
146
+				}
147
+			}
148
+			else {
149
+				$row['last'] = 1;
150
+				$row['lastratio'] = 100;
151
+			}
152
+
153
+			$title2 = '';
154
+			$title3 = '';
155
+			$title4 = '';
156
+			$tagtitle = '';
157
+
158
+			if ($row['coupontype'] == '0') {
159
+				if (0 < $row['enough']) {
160
+					$title2 = '满' . (double) $row['enough'] . '元可用';
161
+				}
162
+				else {
163
+					$title2 = '无金额门槛';
164
+				}
165
+			}
166
+			else {
167
+				if ($row['coupontype'] == '1') {
168
+					if (0 < $row['enough']) {
169
+						$title2 = '充值满' . (double) $row['enough'] . '元可用';
170
+					}
171
+					else {
172
+						$title2 = '无金额门槛';
173
+					}
174
+				}
175
+			}
176
+
177
+			if ($row['coupontype'] == '2') {
178
+				if (0 < $row['enough']) {
179
+					$title2 = '满' . (double) $row['enough'] . '元可用';
180
+				}
181
+				else {
182
+					$title2 = '无金额门槛';
183
+				}
184
+			}
185
+
186
+			if ($row['backtype'] == 0) {
187
+				$title3 = '<span class="subtitle">¥</span>' . (double) $row['deduct'];
188
+
189
+				if ($row['enough'] == '0') {
190
+					$title5 = '消费任意金额立减' . (double) $row['deduct'];
191
+					$row['color'] = 'orange ';
192
+					$tagtitle = '代金券';
193
+				}
194
+				else {
195
+					$title5 = '消费满' . (double) $row['enough'] . '立减' . (double) $row['deduct'];
196
+					$row['color'] = 'blue';
197
+					$tagtitle = '满减券';
198
+				}
199
+			}
200
+			else if ($row['backtype'] == 1) {
201
+				$row['color'] = 'red ';
202
+				$title3 = (double) $row['discount'] . '<span class="subtitle"> 折</span> ';
203
+				$tagtitle = '打折券';
204
+
205
+				if ($row['enough'] == '0') {
206
+					$title5 = '消费任意金额' . '打' . (double) $row['discount'] . '折';
207
+				}
208
+				else {
209
+					$title5 = '消费满' . (double) $row['enough'] . '打' . (double) $row['discount'] . '折';
210
+				}
211
+			}
212
+			else {
213
+				if ($row['backtype'] == 2) {
214
+					if ($row['coupontype'] == '0') {
215
+						$row['color'] = 'red ';
216
+						$tagtitle = '购物返现券';
217
+					}
218
+					else if ($row['coupontype'] == '1') {
219
+						$row['color'] = 'pink ';
220
+						$tagtitle = '充值返现券';
221
+					}
222
+					else {
223
+						if ($row['coupontype'] == '2') {
224
+							$row['color'] = 'red ';
225
+							$tagtitle = '购物返现券';
226
+						}
227
+					}
228
+
229
+					if ($row['enough'] == '0') {
230
+						$title5 = '消费任意金额';
231
+					}
232
+					else {
233
+						$title5 = '消费满' . (double) $row['enough'];
234
+					}
235
+
236
+					if (!empty($row['backmoney']) && 0 < $row['backmoney']) {
237
+						$title3 = '立返';
238
+						$title5 = $title5 . '立返余额';
239
+					}
240
+					else {
241
+						if (!empty($row['backcredit']) && 0 < $row['backcredit']) {
242
+							$title3 = '立返';
243
+							$title5 = $title5 . '立返积分';
244
+						}
245
+						else {
246
+							if (!empty($row['backredpack']) && 0 < $row['backredpack']) {
247
+								$title5 = $title5 . '立返红包';
248
+							}
249
+						}
250
+					}
251
+				}
252
+			}
253
+
254
+			if ($row['tagtitle'] == '') {
255
+				$row['tagtitle'] = $tagtitle;
256
+			}
257
+
258
+			if ($row['timestr'] == '0') {
259
+				$title4 = '永久有效';
260
+			}
261
+			else if ($row['timestr'] == '1') {
262
+				$title4 = '即' . $row['gettypestr'] . '日内' . $row['timedays'] . '天有效';
263
+			}
264
+			else {
265
+				$title4 = $row['timestr'];
266
+			}
267
+
268
+			$row['title2'] = $title2;
269
+			$row['title3'] = $title3;
270
+			$row['title4'] = $title4;
271
+			$row['title5'] = $title5;
272
+		}
273
+
274
+		unset($row);
275
+		return $coupons;
276
+	}
277
+
278
+	public function getwxcard()
279
+	{
280
+		global $_W;
281
+		$merchdata = $this->merchData();
282
+		extract($merchdata);
283
+		$time = time();
284
+		$param = array();
285
+		$param[':uniacid'] = $_W['uniacid'];
286
+		$sql = 'select id,card_id,0 as coupontype,card_type, least_cost,reduce_cost,discount,datetype,begin_timestamp,end_timestamp,fixed_term,fixed_begin_term, merchid,title as couponname,logo_url as thumb ,total_quantity as t,quantity as `last`,tagtitle,settitlecolor,titlecolor,islimitlevel, limitmemberlevels,limitagentlevels,limitpartnerlevels,limitaagentlevels  from ' . tablename('ewei_shop_wxcard');
287
+		$sql .= ' where uniacid=:uniacid';
288
+
289
+		if ($is_openmerch == 0) {
290
+			$sql .= ' and merchid=0';
291
+		}
292
+		else {
293
+			if (!empty($_GPC['merchid'])) {
294
+				$sql .= ' and merchid=:merchid';
295
+				$param[':merchid'] = intval($_GPC['merchid']);
296
+			}
297
+		}
298
+
299
+		$plugin_com = p('commission');
300
+
301
+		if ($plugin_com) {
302
+			$plugin_com_set = $plugin_com->getSet();
303
+
304
+			if (empty($plugin_com_set['level'])) {
305
+				$sql .= ' and ( limitagentlevels = "" or  limitagentlevels is null )';
306
+			}
307
+		}
308
+		else {
309
+			$sql .= ' and ( limitagentlevels = "" or  limitagentlevels is null )';
310
+		}
311
+
312
+		$plugin_globonus = p('globonus');
313
+
314
+		if ($plugin_globonus) {
315
+			$plugin_globonus_set = $plugin_globonus->getSet();
316
+
317
+			if (empty($plugin_globonus_set['open'])) {
318
+				$sql .= ' and ( limitpartnerlevels = ""  or  limitpartnerlevels is null )';
319
+			}
320
+		}
321
+		else {
322
+			$sql .= ' and ( limitpartnerlevels = ""  or  limitpartnerlevels is null )';
323
+		}
324
+
325
+		$plugin_abonus = p('abonus');
326
+
327
+		if ($plugin_abonus) {
328
+			$plugin_abonus_set = $plugin_abonus->getSet();
329
+
330
+			if (empty($plugin_abonus_set['open'])) {
331
+				$sql .= ' and ( limitaagentlevels = "" or  limitaagentlevels is null )';
332
+			}
333
+		}
334
+		else {
335
+			$sql .= ' and ( limitaagentlevels = "" or  limitaagentlevels is null )';
336
+		}
337
+
338
+		$sql .= ' and gettype=1 and quantity>0 and ( datetype = \'DATE_TYPE_FIX_TERM\' or  (datetype=\'DATE_TYPE_FIX_TIME_RANGE\' and end_timestamp>unix_timestamp()))';
339
+
340
+		if (!empty($cateid)) {
341
+			$sql .= ' and catid=' . $cateid;
342
+		}
343
+
344
+		$sql .= ' order by displayorder desc, id desc ';
345
+		$wxcard = pdo_fetchall($sql, $param);
346
+
347
+		if (empty($wxcard)) {
348
+			$wxcard = array();
349
+		}
350
+
351
+		$hascommission = false;
352
+		$plugin_com = p('commission');
353
+
354
+		if ($plugin_com) {
355
+			$plugin_com_set = $plugin_com->getSet();
356
+			$hascommission = !empty($plugin_com_set['level']);
357
+		}
358
+
359
+		$hasglobonus = false;
360
+		$plugin_globonus = p('globonus');
361
+
362
+		if ($plugin_globonus) {
363
+			$plugin_globonus_set = $plugin_globonus->getSet();
364
+			$hasglobonus = !empty($plugin_globonus_set['open']);
365
+		}
366
+
367
+		$hasabonus = false;
368
+		$plugin_abonus = p('abonus');
369
+
370
+		if ($plugin_abonus) {
371
+			$plugin_abonus_set = $plugin_abonus->getSet();
372
+			$hasabonus = !empty($plugin_abonus_set['open']);
373
+		}
374
+
375
+		foreach ($wxcard as $i => &$row) {
376
+			$limitmemberlevels = explode(',', $row['limitmemberlevels']);
377
+			$limitagentlevels = explode(',', $row['limitagentlevels']);
378
+			$limitpartnerlevels = explode(',', $row['limitpartnerlevels']);
379
+			$limitaagentlevels = explode(',', $row['limitaagentlevels']);
380
+			$pass = false;
381
+
382
+			if ($row['islimitlevel'] == 1) {
383
+				$openid = trim($_W['openid']);
384
+				$member = m('member')->getMember($openid);
385
+				if (!empty($row['limitmemberlevels']) || $row['limitmemberlevels'] == '0') {
386
+					$shop = $_W['shopset']['shop'];
387
+
388
+					if (in_array($member['level'], $limitmemberlevels)) {
389
+						$pass = true;
390
+					}
391
+				}
392
+
393
+				if ((!empty($row['limitagentlevels']) || $row['limitagentlevels'] == '0') && $hascommission) {
394
+					if ($member['isagent'] == '1' && $member['status'] == '1') {
395
+						if (in_array($member['agentlevel'], $limitagentlevels)) {
396
+							$pass = true;
397
+						}
398
+					}
399
+				}
400
+
401
+				if ((!empty($row['limitpartnerlevels']) || $row['limitpartnerlevels'] == '0') && $hasglobonus) {
402
+					if ($member['ispartner'] == '1' && $member['partnerstatus'] == '1') {
403
+						if (in_array($member['partnerlevel'], $limitpartnerlevels)) {
404
+							$pass = true;
405
+						}
406
+					}
407
+				}
408
+
409
+				if ((!empty($row['limitaagentlevels']) || $row['limitaagentlevels'] == '0') && $hasabonus) {
410
+					if ($member['isaagent'] == '1' && $member['aagentstatus'] == '1') {
411
+						if (in_array($member['aagentlevel'], $limitaagentlevels)) {
412
+							$pass = true;
413
+						}
414
+					}
415
+				}
416
+			}
417
+			else {
418
+				$pass = true;
419
+			}
420
+
421
+			$row['pass'] = $pass;
422
+			$row['contype'] = 1;
423
+			$totle = $row['t'];
424
+			$last = $row['last'];
425
+			$row['lastratio'] = intval($last / $totle * 100);
426
+			$title2 = '';
427
+			$title3 = '';
428
+			$title4 = '';
429
+			$tagtitle = '';
430
+
431
+			if ($row['coupontype'] == '0') {
432
+				if (0 < $row['least_cost']) {
433
+					$title2 = '满' . (double) $row['least_cost'] / 100 . '元可用';
434
+				}
435
+				else {
436
+					$title2 = '无金额门槛';
437
+				}
438
+			}
439
+
440
+			if ($row['card_type'] == 'CASH') {
441
+				$title3 = '<span class="subtitle">¥</span>' . (double) $row['reduce_cost'] / 100;
442
+
443
+				if (empty($row['least_cost'])) {
444
+					$title5 = '消费任意金额立减' . (double) $row['deduct'];
445
+					$row['color'] = 'orange ';
446
+					$tagtitle = '代金券';
447
+				}
448
+				else {
449
+					$title5 = '消费满' . (double) $row['least_cost'] / 100 . '立减' . (double) $row['reduce_cost'] / 100;
450
+					$row['color'] = 'blue';
451
+					$tagtitle = '满减券';
452
+				}
453
+			}
454
+
455
+			if ($row['card_type'] == 'DISCOUNT') {
456
+				$discount = (double) (100 - intval($row['discount'])) / 10;
457
+				$row['color'] = 'red ';
458
+				$title3 = $discount . '<span class="subtitle"> 折</span> ';
459
+				$tagtitle = '打折券';
460
+				$title5 = '消费任意金额' . '打' . $discount . '折';
461
+			}
462
+
463
+			if ($row['tagtitle'] == '') {
464
+				$row['tagtitle'] = $tagtitle;
465
+			}
466
+
467
+			if ($row['datetype'] == 'DATE_TYPE_FIX_TIME_RANGE') {
468
+				$title4 = date('Y.m.d', $row['begin_timestamp']) . '-' . date('Y.m.d', $row['end_timestamp']);
469
+			}
470
+			else {
471
+				if ($row['datetype'] == 'DATE_TYPE_FIX_TERM') {
472
+					if (empty($row['fixed_begin_term'])) {
473
+						$begin = '当日生效';
474
+					}
475
+					else {
476
+						$begin = '内' . $row['fixed_begin_term'] . '生效,';
477
+					}
478
+
479
+					$title4 = '即领取日' . $begin . $row['fixed_term'] . '天有效';
480
+				}
481
+			}
482
+
483
+			$row['title2'] = $title2;
484
+			$row['title3'] = $title3;
485
+			$row['title4'] = $title4;
486
+			$row['title5'] = $title5;
487
+		}
488
+
489
+		unset($row);
490
+		$wxcardlist = array();
491
+
492
+		foreach ($wxcard as $row) {
493
+			if (!empty($row['pass'])) {
494
+				$wxcardlist[] = $row;
495
+			}
496
+		}
497
+
498
+		return $wxcardlist;
499
+	}
500
+
501
+	public function getlist()
502
+	{
503
+		global $_W;
504
+		global $_GPC;
505
+		$cateid = trim($_GPC['cateid']);
506
+		$coupons = $this->getcoupon($cateid);
507
+		$wxcard = $this->getwxcard($cateid);
508
+		$cards = array_merge($wxcard, $coupons);
509
+		$pindex = max(1, intval($_GPC['page']));
510
+		$psize = 10;
511
+		$cardslist = array();
512
+		$i = 0;
513
+
514
+		while ($i < count($cards)) {
515
+			if (($pindex - 1) * $psize <= $i && $i < $pindex * $psize) {
516
+				$cardslist[] = $cards[$i];
517
+			}
518
+
519
+			++$i;
520
+		}
521
+
522
+		show_json(1, array('list' => $cardslist, 'pagesize' => $psize, 'total' => count($cards)));
523
+	}
524
+
525
+	public function getsignature()
526
+	{
527
+		global $_W;
528
+		global $_GPC;
529
+		$timestamp = time() + '';
530
+		$nonce_str = random(16) + '';
531
+		$card_id = $_GPC['card_id'];
532
+		$openid = $_GPC['openid'];
533
+		$code = empty($_GPC['code']) ? '' : $_GPC['code'];
534
+		$signature = com('wxcard')->getsignature($card_id, $timestamp, $nonce_str, $openid, $code);
535
+		$arr = array('code' => $code, 'openid' => $openid, 'timestamp' => $timestamp, 'nonce_str' => $nonce_str, 'signature' => $signature);
536
+		show_json(1, array('cardExt' => json_encode($arr)));
537
+	}
538
+
539
+	public function updateQuantity()
540
+	{
541
+		global $_W;
542
+		global $_GPC;
543
+		$cardList = $_GPC['cardList'];
544
+		sleep(5);
545
+
546
+		foreach ($cardList as $card) {
547
+			if (com('wxcard')) {
548
+				com('wxcard')->wxCardUpdateQuantity($card['cardId']);
549
+			}
550
+		}
551
+
552
+		show_json(1);
553
+	}
554
+}
555
+
556
+?>

+ 790 - 0
addons/ewei_shopv2/core/mobile/sale/coupon/my.php Parādīt failu

@@ -0,0 +1,790 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class My_EweiShopV2Page extends MobileLoginPage
7
+{
8
+	public function main()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$openid = $_W['openid'];
13
+		$set = m('common')->getPluginset('coupon');
14
+		com('coupon')->setShare();
15
+		include $this->template();
16
+	}
17
+
18
+	public function detail()
19
+	{
20
+		global $_W;
21
+		global $_GPC;
22
+		$id = intval($_GPC['id']);
23
+		$data = pdo_fetch('select * from ' . tablename('ewei_shop_coupon_data') . ' where id=:id and uniacid=:uniacid limit 1', array(':id' => $id, ':uniacid' => $_W['uniacid']));
24
+
25
+		if (empty($data)) {
26
+			if (empty($coupon)) {
27
+				header('location: ' . mobileUrl('sale/coupon/my'));
28
+				exit();
29
+			}
30
+		}
31
+
32
+		$coupon = pdo_fetch('select * from ' . tablename('ewei_shop_coupon') . ' where id=:id and uniacid=:uniacid limit 1', array(':id' => $data['couponid'], ':uniacid' => $_W['uniacid']));
33
+
34
+		if (empty($coupon)) {
35
+			header('location: ' . mobileUrl('sale/coupon/my'));
36
+			exit();
37
+		}
38
+
39
+		$coupon['gettime'] = $data['gettime'];
40
+		$coupon['back'] = $data['back'];
41
+		$coupon['backtime'] = $data['backtime'];
42
+		$coupon['used'] = $data['used'];
43
+		$coupon['usetime'] = $data['usetime'];
44
+		$time = time();
45
+		$coupon = com('coupon')->setMyCoupon($coupon, $time);
46
+		$commonset = m('common')->getPluginset('coupon');
47
+
48
+		if ($coupon['descnoset'] == '0') {
49
+			if ($coupon['coupontype'] == '0') {
50
+				$coupon['desc'] = $commonset['consumedesc'];
51
+			}
52
+			else if ($coupon['coupontype'] == '1') {
53
+				$coupon['desc'] = $commonset['rechargedesc'];
54
+			}
55
+			else {
56
+				$coupon['desc'] = $commonset['consumedesc'];
57
+			}
58
+		}
59
+
60
+		$title2 = '';
61
+		$title3 = '';
62
+
63
+		if ($coupon['coupontype'] == '0') {
64
+			if (0 < $coupon['enough']) {
65
+				$title2 = '满' . (double) $coupon['enough'] . '元';
66
+			}
67
+			else {
68
+				$title2 = '购物任意金额';
69
+			}
70
+		}
71
+		else if ($coupon['coupontype'] == '1') {
72
+			if (0 < $coupon['enough']) {
73
+				$title2 = '充值满' . (double) $coupon['enough'] . '元';
74
+			}
75
+			else {
76
+				$title2 = '充值任意金额';
77
+			}
78
+		}
79
+		else {
80
+			if ($coupon['coupontype'] == '2') {
81
+				if (0 < $coupon['enough']) {
82
+					$title2 = '满' . (double) $coupon['enough'] . '元';
83
+				}
84
+				else {
85
+					$title2 = '购物任意金额';
86
+				}
87
+			}
88
+		}
89
+
90
+		if ($coupon['backtype'] == 0) {
91
+			if ($coupon['enough'] == '0') {
92
+				$coupon['color'] = 'orange ';
93
+			}
94
+			else {
95
+				$coupon['color'] = 'blue';
96
+			}
97
+
98
+			$title3 = '减' . (double) $coupon['deduct'] . '元';
99
+		}
100
+
101
+		if ($coupon['backtype'] == 1) {
102
+			$coupon['color'] = 'red ';
103
+			$title3 = '打' . (double) $coupon['discount'] . '折 ';
104
+		}
105
+
106
+		if ($coupon['backtype'] == 2) {
107
+			if ($coupon['coupontype'] == '0' || $coupon['coupontype'] == '2') {
108
+				$coupon['color'] = 'red ';
109
+			}
110
+			else {
111
+				$coupon['color'] = 'pink ';
112
+			}
113
+
114
+			if (!empty($coupon['backmoney']) && 0 < $coupon['backmoney']) {
115
+				$title3 = $title3 . '送' . $coupon['backmoney'] . '元余额 ';
116
+			}
117
+
118
+			if (!empty($coupon['backcredit']) && 0 < $coupon['backcredit']) {
119
+				$title3 = $title3 . '送' . $coupon['backcredit'] . '积分 ';
120
+			}
121
+
122
+			if (!empty($coupon['backredpack']) && 0 < $coupon['backredpack']) {
123
+				$title3 = $title3 . '送' . $coupon['backredpack'] . '元红包 ';
124
+			}
125
+		}
126
+
127
+		if ($coupon['past'] || !empty($data['used'])) {
128
+			$coupon['color'] = 'disa';
129
+		}
130
+
131
+		$coupon['title2'] = $title2;
132
+		$coupon['title3'] = $title3;
133
+		$goods = array();
134
+		$category = array();
135
+
136
+		if ($coupon['limitgoodtype'] != 0) {
137
+			if (!empty($coupon['limitgoodids'])) {
138
+				$where = 'and id in(' . $coupon['limitgoodids'] . ')';
139
+			}
140
+
141
+			$goods = pdo_fetchall('select `title` from ' . tablename('ewei_shop_goods') . ' where uniacid=:uniacid ' . $where, array(':uniacid' => $_W['uniacid']), 'id');
142
+		}
143
+
144
+		if ($coupon['limitgoodcatetype'] != 0) {
145
+			if (!empty($coupon['limitgoodcateids'])) {
146
+				$where = 'and id in(' . $coupon['limitgoodcateids'] . ')';
147
+			}
148
+
149
+			$category = pdo_fetchall('select `name`  from ' . tablename('ewei_shop_category') . ' where uniacid=:uniacid   ' . $where, array(':uniacid' => $_W['uniacid']), 'id');
150
+		}
151
+
152
+		$num = pdo_fetchcolumn('select ifnull(count(*),0) from ' . tablename('ewei_shop_coupon_data') . ' where couponid=:couponid and openid=:openid and uniacid=:uniacid and used=0 ', array(':couponid' => $coupon['id'], ':openid' => $_W['openid'], ':uniacid' => $_W['uniacid']));
153
+		$canuse = !$coupon['past'] && empty($data['used']);
154
+
155
+		if ($coupon['coupontype'] == 0) {
156
+			$useurl = mobileUrl('sale/coupon/my/showcoupongoods', array('id' => $id));
157
+		}
158
+		else if ($coupon['coupontype'] == 1) {
159
+			$useurl = mobileUrl('member/recharge');
160
+		}
161
+		else {
162
+			if ($coupon['coupontype'] == 2) {
163
+				$useurl = mobileUrl('sale/coupon/my');
164
+			}
165
+		}
166
+
167
+		$set = $_W['shopset']['coupon'];
168
+		com('coupon')->setShare();
169
+		include $this->template();
170
+	}
171
+
172
+	public function getlist()
173
+	{
174
+		global $_W;
175
+		global $_GPC;
176
+		$openid = $_W['openid'];
177
+		$cate = trim($_GPC['cate']);
178
+		$check = 0;
179
+
180
+		if (!empty($cate)) {
181
+			if ($cate == 'used') {
182
+				$used = 1;
183
+				$check = 1;
184
+			}
185
+			else {
186
+				$past = 1;
187
+				$check = 2;
188
+			}
189
+		}
190
+
191
+		$pindex = max(1, intval($_GPC['page']));
192
+		$psize = 10;
193
+		$time = time();
194
+		$sql = 'select d.id,d.couponid,d.gettime,c.timelimit,c.coupontype,c.timedays,c.timestart,c.timeend,c.thumb,c.couponname,c.enough,c.backtype,c.deduct,c.discount,c.backmoney,c.backcredit,c.backredpack,c.bgcolor,c.thumb,c.merchid,c.tagtitle,c.settitlecolor,c.titlecolor from ' . tablename('ewei_shop_coupon_data') . ' d';
195
+		$sql .= ' inner join ' . tablename('ewei_shop_coupon') . ' c on d.couponid = c.id';
196
+		$sql .= ' where d.openid=:openid and d.uniacid=:uniacid ';
197
+
198
+		if (!empty($past)) {
199
+			$sql .= ' and  ( (c.timelimit =0 and c.timedays<>0 and  c.timedays*86400 + d.gettime <unix_timestamp()) or (c.timelimit=1 and c.timeend<unix_timestamp() ))';
200
+		}
201
+		else if (!empty($used)) {
202
+			$sql .= ' and d.used =1 ';
203
+		}
204
+		else {
205
+			if (empty($used)) {
206
+				$sql .= ' and (   (c.timelimit = 0 and ( c.timedays=0 or c.timedays*86400 + d.gettime >=unix_timestamp() ) )  or  (c.timelimit =1 and c.timeend>=' . $time . ')) and  d.used =0 ';
207
+			}
208
+		}
209
+
210
+		$total = pdo_fetchcolumn($sql, array(':openid' => $openid, ':uniacid' => $_W['uniacid']));
211
+		$sql .= ' order by d.gettime desc  LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
212
+		$coupons = set_medias(pdo_fetchall($sql, array(':openid' => $openid, ':uniacid' => $_W['uniacid'])), 'thumb');
213
+		pdo_update('ewei_shop_coupon_data', array('isnew' => 0), array('uniacid' => $_W['uniacid'], 'openid' => $_W['openid']));
214
+
215
+		if (empty($coupons)) {
216
+			$coupons = array();
217
+		}
218
+
219
+		foreach ($coupons as $i => &$row) {
220
+			$row = com('coupon')->setMyCoupon($row, $time);
221
+			$title2 = '';
222
+
223
+			if ($row['coupontype'] == '0') {
224
+				if (0 < $row['enough']) {
225
+					$title2 = '满' . (double) $row['enough'] . '元可用';
226
+					$title5 = '消费满' . (double) $row['enough'];
227
+				}
228
+				else {
229
+					$title2 = '无金额门槛';
230
+					$title5 = '消费任意金额';
231
+				}
232
+			}
233
+			else if ($row['coupontype'] == '1') {
234
+				if (0 < $row['enough']) {
235
+					$title2 = '充值满' . (double) $row['enough'] . '元可用';
236
+					$title5 = '充值满' . (double) $row['enough'];
237
+				}
238
+				else {
239
+					$title2 = '无金额门槛';
240
+					$title5 = '充值任意金额';
241
+				}
242
+			}
243
+			else {
244
+				if ($row['coupontype'] == '2') {
245
+					if (0 < $row['enough']) {
246
+						$title2 = '满' . (double) $row['enough'] . '元可用';
247
+						$title5 = '消费满' . (double) $row['enough'];
248
+					}
249
+					else {
250
+						$title2 = '无金额门槛';
251
+						$title5 = '消费任意金额';
252
+					}
253
+				}
254
+			}
255
+
256
+			if ($row['backtype'] == 0) {
257
+				$title3 = '<span class="subtitle">¥</span>' . (double) $row['deduct'];
258
+				$title5 = $title5 . '立减' . (double) $row['deduct'];
259
+
260
+				if ($row['enough'] == '0') {
261
+					$row['color'] = 'orange ';
262
+					$tagtitle = '代金券';
263
+				}
264
+				else {
265
+					$row['color'] = 'blue';
266
+					$tagtitle = '满减券';
267
+				}
268
+			}
269
+
270
+			if ($row['backtype'] == 1) {
271
+				$row['color'] = 'red ';
272
+				$title3 = (double) $row['discount'] . '折 ';
273
+				$title5 = $title5 . '打' . (double) $row['discount'] . '折 ';
274
+				$tagtitle = '打折券';
275
+			}
276
+
277
+			if ($row['backtype'] == 2) {
278
+				if ($row['coupontype'] == '0') {
279
+					$row['color'] = 'red ';
280
+					$tagtitle = '购物返现券';
281
+				}
282
+				else if ($row['coupontype'] == '1') {
283
+					$row['color'] = 'pink ';
284
+					$tagtitle = '充值返现券';
285
+				}
286
+				else {
287
+					if ($row['coupontype'] == '2') {
288
+						$row['color'] = 'red ';
289
+						$tagtitle = '购物返现券';
290
+					}
291
+				}
292
+
293
+				if (!empty($row['backmoney']) && 0 < $row['backmoney']) {
294
+					$title3 = '立返';
295
+					$title5 = '立返余额';
296
+				}
297
+
298
+				if (!empty($row['backcredit']) && 0 < $row['backcredit']) {
299
+					$title3 = '立返';
300
+					$title5 = '立返积分';
301
+				}
302
+
303
+				if (!empty($row['backredpack']) && 0 < $row['backredpack']) {
304
+					$title3 = '立返';
305
+					$title5 = '立返红包';
306
+				}
307
+			}
308
+
309
+			if ($row['tagtitle'] == '') {
310
+				$row['tagtitle'] = $tagtitle;
311
+			}
312
+
313
+			if ($past == 1) {
314
+				$row['color'] = 'disa';
315
+			}
316
+
317
+			$row['check'] = $check;
318
+			$row['title2'] = $title2;
319
+			$row['title3'] = $title3;
320
+			$row['title5'] = $title5;
321
+		}
322
+
323
+		unset($row);
324
+		show_json(1, array('list' => $coupons, 'pagesize' => $psize, 'total' => $total));
325
+	}
326
+
327
+	public function showcoupons()
328
+	{
329
+		global $_W;
330
+		global $_GPC;
331
+		$key = $_GPC['key'];
332
+		$openid = $_W['openid'];
333
+		$time = time();
334
+		$sql = 'select d.id,d.couponid,d.gettime,c.timelimit,c.coupontype,c.timedays,c.timestart,c.timeend,c.thumb,c.couponname,c.enough,c.backtype,c.deduct,c.discount,c.backmoney,c.backcredit,c.backredpack,c.bgcolor,c.thumb,c.merchid,c.tagtitle,c.settitlecolor,c.titlecolor from ' . tablename('ewei_shop_coupon_sendshow') . ' cs';
335
+		$sql .= ' inner join ' . tablename('ewei_shop_coupon_data') . ' d  on d.id=cs.coupondataid';
336
+		$sql .= ' inner join ' . tablename('ewei_shop_coupon') . ' c on d.couponid = c.id ';
337
+		$sql .= ' where cs.openid=:openid and cs.uniacid=:uniacid and showkey=:key ';
338
+		$sql .= ' order by d.gettime desc  ';
339
+		$coupons = set_medias(pdo_fetchall($sql, array(':openid' => $openid, ':uniacid' => $_W['uniacid'], ':key' => $key)), 'thumb');
340
+
341
+		if (empty($coupons)) {
342
+			$coupons = array();
343
+		}
344
+
345
+		foreach ($coupons as $i => &$row) {
346
+			$imgname = 'ling';
347
+			$row = com('coupon')->setMyCoupon($row, $time);
348
+			$title2 = '';
349
+
350
+			if ($row['coupontype'] == '0') {
351
+				if (0 < $row['enough']) {
352
+					$title2 = '消费满' . (double) $row['enough'] . '元';
353
+				}
354
+				else {
355
+					$title2 = '消费';
356
+				}
357
+			}
358
+			else if ($row['coupontype'] == '1') {
359
+				if (0 < $row['enough']) {
360
+					$title2 = '充值满' . (double) $row['enough'] . '元';
361
+				}
362
+				else {
363
+					$title2 = '充值';
364
+				}
365
+			}
366
+			else {
367
+				if ($row['coupontype'] == '2') {
368
+					if (0 < $row['enough']) {
369
+						$title2 = '消费满' . (double) $row['enough'] . '元';
370
+					}
371
+					else {
372
+						$title2 = '消费';
373
+					}
374
+				}
375
+			}
376
+
377
+			if ($row['backtype'] == 0) {
378
+				$title2 = $title2 . '立减' . (double) $row['deduct'] . '元';
379
+
380
+				if ($row['enough'] == '0') {
381
+					$row['color'] = 'orange ';
382
+					$tagtitle = '代金券';
383
+				}
384
+				else {
385
+					$row['color'] = 'blue';
386
+					$tagtitle = '满减券';
387
+				}
388
+			}
389
+
390
+			if ($row['backtype'] == 1) {
391
+				$row['color'] = 'red ';
392
+				$title2 = $title2 . '打' . (double) $row['discount'] . '折';
393
+				$tagtitle = '打折券';
394
+			}
395
+
396
+			if ($row['backtype'] == 2) {
397
+				if ($row['coupontype'] == '0') {
398
+					$row['color'] = 'red ';
399
+					$tagtitle = '购物返现券';
400
+				}
401
+				else if ($row['coupontype'] == '1') {
402
+					$row['color'] = 'pink ';
403
+					$tagtitle = '充值返现券';
404
+				}
405
+				else {
406
+					if ($row['coupontype'] == '2') {
407
+						$row['color'] = 'red ';
408
+						$tagtitle = '购物返现券';
409
+					}
410
+				}
411
+
412
+				if (!empty($row['backmoney']) && 0 < $row['backmoney']) {
413
+					$title2 = $title2 . '送' . $row['discount'] . '元余额';
414
+				}
415
+
416
+				if (!empty($row['backcredit']) && 0 < $row['backcredit']) {
417
+					$title2 = $title2 . '送' . $row['discount'] . '积分';
418
+				}
419
+
420
+				if (!empty($row['backredpack']) && 0 < $row['backredpack']) {
421
+					$title2 = $title2 . '送' . $row['discount'] . '元红包';
422
+				}
423
+			}
424
+
425
+			if ($row['tagtitle'] == '') {
426
+				$row['tagtitle'] = $tagtitle;
427
+			}
428
+
429
+			$check = 0;
430
+
431
+			if ($row['used'] == 1) {
432
+				$check = 1;
433
+				$imgname = 'used';
434
+			}
435
+			else {
436
+				if ($row['timelimit'] == 0 && $row['timedays'] != 0 && $row['timedays'] * 86400 + $row['gettime'] < time() || $row['timelimit'] == 1 && $row['timeend'] < time()) {
437
+					$check = 2;
438
+					$row['color'] = 'disa';
439
+					$imgname = 'past';
440
+				}
441
+			}
442
+
443
+			$row['imgname'] = $imgname;
444
+			$row['check'] = $check;
445
+			$row['title2'] = $title2;
446
+		}
447
+
448
+		unset($row);
449
+		include $this->template();
450
+	}
451
+
452
+	public function showcoupons2()
453
+	{
454
+		global $_W;
455
+		global $_GPC;
456
+		$id = intval($_GPC['id']);
457
+		$data = pdo_fetch('select c.*  from ' . tablename('ewei_shop_coupon_data') . '  cd inner join  ' . tablename('ewei_shop_coupon') . ' c on cd.couponid = c.id  where cd.id=:id and cd.uniacid=:uniacid and coupontype =0  limit 1', array(':id' => $id, ':uniacid' => $_W['uniacid']));
458
+
459
+		if (empty($data)) {
460
+			if (empty($coupon)) {
461
+				header('location: ' . mobileUrl('sale/coupon/my'));
462
+				exit();
463
+			}
464
+		}
465
+
466
+		if (7 < mb_strlen($data['couponname'], 'utf-8')) {
467
+			$data['couponname'] = mb_substr($data['couponname'], 0, 7, 'utf-8') . '...';
468
+		}
469
+
470
+		$title1 = '';
471
+		$title2 = '';
472
+
473
+		if ($data['backtype'] == 0) {
474
+			$title1 = '<span>¥</span>' . (double) $data['deduct'];
475
+		}
476
+		else if ($data['backtype'] == 1) {
477
+			$title1 = (double) $data['discount'] . '<span>折</span>';
478
+		}
479
+		else {
480
+			if ($data['backtype'] == 2) {
481
+				if (!empty($data['backmoney']) && 0 < $data['backmoney']) {
482
+					$title1 = '送' . $data['backmoney'] . '元余额';
483
+				}
484
+
485
+				if (!empty($data['backcredit']) && 0 < $data['backcredit']) {
486
+					$title1 .= '送' . $data['backcredit'] . '积分';
487
+				}
488
+
489
+				if (!empty($data['backredpack']) && 0 < $data['backredpack']) {
490
+					$title1 .= '送' . $data['backredpack'] . '元红包';
491
+				}
492
+			}
493
+		}
494
+
495
+		if (0 < $data['enough']) {
496
+			$title2 = '满' . (double) $data['enough'] . '元使用';
497
+		}
498
+		else {
499
+			$title2 = '无金额门槛';
500
+		}
501
+
502
+		$goods = array();
503
+		$params = array(':uniacid' => $_W['uniacid']);
504
+		$sql = 'select  distinct  g.*  from ';
505
+		$table = '';
506
+		if ($data['limitgoodcatetype'] == 1 && !empty($data['limitgoodcateids'])) {
507
+			$limitcateids = explode(',', $data['limitgoodcateids']);
508
+
509
+			if (0 < count($limitcateids)) {
510
+				$table = '(';
511
+				$i = 0;
512
+
513
+				foreach ($limitcateids as $cateid) {
514
+					++$i;
515
+
516
+					if (1 < $i) {
517
+						$table .= ' union all ';
518
+					}
519
+
520
+					$table .= 'select * from ' . tablename('ewei_shop_goods') . ' where FIND_IN_SET(' . $cateid . ',cates) and deleted =0';
521
+				}
522
+
523
+				$table .= ') g';
524
+			}
525
+			else {
526
+				$table = tablename('ewei_shop_goods') . ' g';
527
+			}
528
+		}
529
+		else {
530
+			$table = tablename('ewei_shop_goods') . ' g';
531
+		}
532
+
533
+		$where = ' where  g.uniacid=:uniacid and g.bargain =0 and g.status =1 and g.deleted = 0 ';
534
+		if ($data['limitgoodtype'] == 1 && !empty($data['limitgoodids'])) {
535
+			$where .= ' and g.id in (' . $data['limitgoodids'] . ') ';
536
+		}
537
+
538
+		if (!empty($data['merchid'])) {
539
+			$where .= ' and g.merchid = ' . $data['merchid'] . ' and g.checked=0';
540
+		}
541
+
542
+		$where .= ' ORDER BY RAND() LIMIT 5 ';
543
+		$sql = $sql . $table . $where;
544
+		$goods = pdo_fetchall($sql, $params);
545
+
546
+		foreach ($goods as $i => &$row) {
547
+			$couponprice = (double) $row['minprice'];
548
+
549
+			if ($data['backtype'] == 0) {
550
+				$couponprice = round($couponprice - (double) $data['deduct'], 2);
551
+			}
552
+
553
+			if ($data['backtype'] == 1) {
554
+				$couponprice = (double) $couponprice * (floatval($data['discount']) / 10);
555
+			}
556
+
557
+			if ($couponprice < 0) {
558
+				$couponprice = 0;
559
+			}
560
+
561
+			$row['couponprice'] = $couponprice;
562
+		}
563
+
564
+		unset($row);
565
+		$goods = set_medias($goods, 'thumb');
566
+		include $this->template();
567
+	}
568
+
569
+	public function showcoupons3()
570
+	{
571
+		global $_W;
572
+		global $_GPC;
573
+		$key = $_GPC['key'];
574
+		$openid = $_W['openid'];
575
+		$time = time();
576
+		$sql = 'select d.id,d.couponid,d.gettime,c.timelimit,c.limitgoodcatetype,c.limitgoodcateids,c.coupontype,c.limitgoodtype,c.limitgoodids,c.timedays,c.timestart,c.timeend,c.thumb,c.couponname,c.enough,c.backtype,c.deduct,c.discount,c.backmoney,c.backcredit,c.backredpack,c.bgcolor,c.thumb,c.merchid,c.tagtitle,c.settitlecolor,c.titlecolor from ' . tablename('ewei_shop_coupon_sendshow') . ' cs';
577
+		$sql .= ' inner join ' . tablename('ewei_shop_coupon_data') . ' d  on d.id=cs.coupondataid';
578
+		$sql .= ' inner join ' . tablename('ewei_shop_coupon') . ' c on d.couponid = c.id ';
579
+		$sql .= ' where cs.openid=:openid and cs.uniacid=:uniacid and showkey=:key ';
580
+		$sql .= ' order by d.gettime desc  ';
581
+		$coupons = set_medias(pdo_fetchall($sql, array(':openid' => $openid, ':uniacid' => $_W['uniacid'], ':key' => $key)), 'thumb');
582
+
583
+		if (empty($coupons)) {
584
+			$coupons = array();
585
+		}
586
+
587
+		foreach ($coupons as $i => &$row) {
588
+			if (0 < $row['enough']) {
589
+				$row['title2'] = '满' . (double) $row['enough'] . '元使用';
590
+			}
591
+			else {
592
+				$row['title2'] = '无金额门槛';
593
+			}
594
+
595
+			if ($row['coupontype'] == 0 || $row['coupontype'] == 2) {
596
+				$row['title3'] = '优惠券';
597
+
598
+				if ($row['backtype'] == 0) {
599
+					$row['title1'] = '<span>¥</span>' . (double) $row['deduct'];
600
+				}
601
+				else if ($row['backtype'] == 1) {
602
+					$row['title1'] = (double) $row['discount'] . '<span>折</span>';
603
+				}
604
+				else {
605
+					if ($row['backtype'] == 2) {
606
+						if (!empty($row['backmoney']) && 0 < $row['backmoney']) {
607
+							$row['title1'] = '送' . $row['backmoney'] . '元余额';
608
+						}
609
+
610
+						if (!empty($row['backcredit']) && 0 < $row['backcredit']) {
611
+							$row['title1'] .= '送' . $row['backcredit'] . '积分';
612
+						}
613
+
614
+						if (!empty($row['backredpack']) && 0 < $row['backredpack']) {
615
+							$row['title1'] .= '送' . $row['backredpack'] . '元红包';
616
+						}
617
+					}
618
+				}
619
+
620
+				$goods = array();
621
+				$params = array(':uniacid' => $_W['uniacid']);
622
+				$sql = 'select  distinct  g.*  from ';
623
+				$table = '';
624
+				if ($row['limitgoodcatetype'] == 1 && !empty($row['limitgoodcateids'])) {
625
+					$limitcateids = explode(',', $row['limitgoodcateids']);
626
+
627
+					if (0 < count($limitcateids)) {
628
+						$table = '(';
629
+						$i = 0;
630
+
631
+						foreach ($limitcateids as $cateid) {
632
+							++$i;
633
+
634
+							if (1 < $i) {
635
+								$table .= ' union all ';
636
+							}
637
+
638
+							$table .= 'select * from ' . tablename('ewei_shop_goods') . ' where FIND_IN_SET(' . $cateid . ',cates) and deleted = 0';
639
+						}
640
+
641
+						$table .= ') g';
642
+					}
643
+					else {
644
+						$table = tablename('ewei_shop_goods') . ' g';
645
+					}
646
+				}
647
+				else {
648
+					$table = tablename('ewei_shop_goods') . ' g';
649
+				}
650
+
651
+				$where = ' where  g.uniacid=:uniacid and g.bargain =0 and g.status =1 and g.deleted = 0';
652
+				if ($row['limitgoodtype'] == 1 && !empty($row['limitgoodids'])) {
653
+					$where .= ' and g.id in (' . $row['limitgoodids'] . ') ';
654
+				}
655
+
656
+				if (!empty($row['merchid'])) {
657
+					$where .= ' and g.merchid = ' . $row['merchid'] . ' and g.checked=0';
658
+				}
659
+
660
+				$where .= ' ORDER BY RAND() LIMIT 5 ';
661
+				$sql = $sql . $table . $where;
662
+				$goods = pdo_fetchall($sql, $params);
663
+
664
+				foreach ($goods as $i => &$row2) {
665
+					$couponprice = (double) $row2['minprice'];
666
+
667
+					if ($row['backtype'] == 0) {
668
+						$couponprice = round($couponprice - (double) $row['deduct'], 2);
669
+					}
670
+
671
+					if ($row['backtype'] == 1) {
672
+						$couponprice = (double) $couponprice * (floatval($row['discount']) / 10);
673
+					}
674
+
675
+					if ($couponprice < 0) {
676
+						$couponprice = 0;
677
+					}
678
+
679
+					$row2['couponprice'] = $couponprice;
680
+				}
681
+
682
+				unset($row2);
683
+				$goods = set_medias($goods, 'thumb');
684
+				$row['goods'] = $goods;
685
+			}
686
+			else {
687
+				$row['title3'] = '充值卷';
688
+
689
+				if ($row['backtype'] == 2) {
690
+					if (!empty($row['backmoney']) && 0 < $row['backmoney']) {
691
+						$row['title1'] = '送' . $row['backmoney'] . '元余额';
692
+					}
693
+
694
+					if (!empty($row['backcredit']) && 0 < $row['backcredit']) {
695
+						$row['title1'] .= '送' . $row['backcredit'] . '积分';
696
+					}
697
+
698
+					if (!empty($row['backredpack']) && 0 < $row['backredpack']) {
699
+						$row['title1'] .= '送' . $row['backredpack'] . '元红包';
700
+					}
701
+				}
702
+			}
703
+		}
704
+
705
+		include $this->template();
706
+	}
707
+
708
+	public function showcoupongoods()
709
+	{
710
+		global $_W;
711
+		global $_GPC;
712
+		$id = intval($_GPC['id']);
713
+		$data = pdo_fetch('select c.*  from ' . tablename('ewei_shop_coupon_data') . '  cd inner join  ' . tablename('ewei_shop_coupon') . ' c on cd.couponid = c.id  where cd.id=:id and cd.uniacid=:uniacid and coupontype =0  limit 1', array(':id' => $id, ':uniacid' => $_W['uniacid']));
714
+
715
+		if (empty($data)) {
716
+			if (empty($coupon)) {
717
+				header('location: ' . mobileUrl('sale/coupon/my'));
718
+				exit();
719
+			}
720
+		}
721
+
722
+		$merchid = 0;
723
+
724
+		if (!empty($data['merchid'])) {
725
+			$merchid = $data['merchid'];
726
+		}
727
+
728
+		if (8 < mb_strlen($data['couponname'], 'utf-8')) {
729
+			$data['couponname'] = mb_substr($data['couponname'], 0, 8, 'utf-8') . '..';
730
+		}
731
+
732
+		$allcategory = m('shop')->getCategory();
733
+		$catlevel = intval($_W['shopset']['category']['level']);
734
+		$opencategory = true;
735
+		$plugin_commission = p('commission');
736
+		if ($plugin_commission && 0 < intval($_W['shopset']['commission']['level'])) {
737
+			$mid = intval($_GPC['mid']);
738
+
739
+			if (!empty($mid)) {
740
+				$shop = p('commission')->getShop($mid);
741
+
742
+				if (empty($shop['selectcategory'])) {
743
+					$opencategory = false;
744
+				}
745
+			}
746
+		}
747
+
748
+		include $this->template();
749
+	}
750
+
751
+	public function get_list()
752
+	{
753
+		global $_GPC;
754
+		global $_W;
755
+		$args = array('pagesize' => 10, 'page' => intval($_GPC['page']), 'isnew' => trim($_GPC['isnew']), 'ishot' => trim($_GPC['ishot']), 'isrecommand' => trim($_GPC['isrecommand']), 'isdiscount' => trim($_GPC['isdiscount']), 'istime' => trim($_GPC['istime']), 'issendfree' => trim($_GPC['issendfree']), 'keywords' => trim($_GPC['keywords']), 'cate' => trim($_GPC['cate']), 'order' => trim($_GPC['order']), 'by' => trim($_GPC['by']), 'couponid' => trim($_GPC['couponid']), 'merchid' => intval($_GPC['merchid']));
756
+		$plugin_commission = p('commission');
757
+		if ($plugin_commission && 0 < intval($_W['shopset']['commission']['level']) && empty($_W['shopset']['commission']['closemyshop']) && !empty($_W['shopset']['commission']['select_goods'])) {
758
+			$mid = intval($_GPC['mid']);
759
+
760
+			if (!empty($mid)) {
761
+				$shop = p('commission')->getShop($mid);
762
+
763
+				if (!empty($shop['selectgoods'])) {
764
+					$args['ids'] = $shop['goodsids'];
765
+				}
766
+			}
767
+		}
768
+
769
+		$this->_condition($args);
770
+	}
771
+
772
+	private function _condition($args)
773
+	{
774
+		global $_GPC;
775
+		$merch_plugin = p('merch');
776
+		$merch_data = m('common')->getPluginset('merch');
777
+		if ($merch_plugin && $merch_data['is_openmerch']) {
778
+			$args['merchid'] = intval($_GPC['merchid']);
779
+		}
780
+
781
+		if (isset($_GPC['nocommission'])) {
782
+			$args['nocommission'] = intval($_GPC['nocommission']);
783
+		}
784
+
785
+		$goods = m('goods')->getListbyCoupon($args);
786
+		show_json(1, array('list' => $goods['list'], 'total' => $goods['total'], 'pagesize' => $args['pagesize']));
787
+	}
788
+}
789
+
790
+?>

+ 34 - 0
addons/ewei_shopv2/core/mobile/sale/coupon/quickget.php Parādīt failu

@@ -0,0 +1,34 @@
1
+<?php  if( !defined("IN_IA") ) 
2
+{
3
+	exit( "Access Denied" );
4
+}
5
+class Quickget_EweiShopV2Page extends MobileLoginPage 
6
+{
7
+	public function main() 
8
+	{
9
+		global $_W;
10
+		global $_GPC;
11
+		$id = intval($_GPC["id"]);
12
+		$openid = $_W["openid"];
13
+		$member = m("member")->getMember($openid);
14
+		if( empty($member) ) 
15
+		{
16
+			header("location: " . mobileUrl());
17
+			exit();
18
+		}
19
+		$time = time();
20
+		$coupon = pdo_fetch("select * from " . tablename("ewei_shop_coupon") . " where  1 and uniacid=:uniacid  and id=:id", array( ":uniacid" => $_W["uniacid"], ":id" => $id ));
21
+		if( empty($coupon) || empty($coupon["quickget"]) ) 
22
+		{
23
+			header("location: " . mobileUrl());
24
+			exit();
25
+		}
26
+		$couponlog = array( "uniacid" => $_W["uniacid"], "openid" => $member["openid"], "logno" => m("common")->createNO("coupon_log", "logno", "CC"), "couponid" => $id, "status" => 1, "paystatus" => -1, "creditstatus" => -1, "createtime" => time(), "getfrom" => 8 );
27
+		pdo_insert("ewei_shop_coupon_log", $couponlog);
28
+		$data = array( "uniacid" => $_W["uniacid"], "openid" => $member["openid"], "couponid" => $id, "gettype" => 8, "gettime" => time() );
29
+		pdo_insert("ewei_shop_coupon_data", $data);
30
+		$id = pdo_insertid();
31
+		header("location: " . mobileUrl("sale/coupon/my/showcoupons2", array( "id" => $id )));
32
+	}
33
+}
34
+?>

+ 19 - 0
addons/ewei_shopv2/core/mobile/sale/coupon/show.php Parādīt failu

@@ -0,0 +1,19 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Show_EweiShopV2Page extends MobileLoginPage
7
+{
8
+	public function main()
9
+	{
10
+		include $this->template('sale/coupon/my/showcoupons');
11
+	}
12
+
13
+	public function main2()
14
+	{
15
+		include $this->template('sale/coupon/my/showcoupons2');
16
+	}
17
+}
18
+
19
+?>

+ 37 - 0
addons/ewei_shopv2/core/mobile/sale/coupon/util.php Parādīt failu

@@ -0,0 +1,37 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Util_EweiShopV2Page extends MobilePage
7
+{
8
+	public function query()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$type = intval($_GPC['type']);
13
+		$money = floatval($_GPC['money']);
14
+		$merchs = $_GPC['merchs'];
15
+		$goods = $_GPC['goods'];
16
+
17
+		if ($type == 0) {
18
+			$list = com_run('coupon::getAvailableCoupons', $type, 0, $merchs, $goods);
19
+			$list2 = com_run('wxcard::getAvailableWxcards', $type, 0, $merchs, $goods);
20
+		}
21
+		else {
22
+			if ($type == 1) {
23
+				$list = com_run('coupon::getAvailableCoupons', $type, $money, $merchs);
24
+				$list2 = array();
25
+			}
26
+		}
27
+
28
+		show_json(1, array('coupons' => $list, 'wxcards' => $list2));
29
+	}
30
+
31
+	public function picker()
32
+	{
33
+		include $this->template();
34
+	}
35
+}
36
+
37
+?>

+ 399 - 0
addons/ewei_shopv2/core/mobile/sale/sendticket/share.php Parādīt failu

@@ -0,0 +1,399 @@
1
+<?php  if( !defined("IN_IA") ) 
2
+{
3
+	exit( "Access Denied" );
4
+}
5
+class Share_EweiShopV2Page extends MobileLoginPage 
6
+{
7
+	public function getStatus() 
8
+	{
9
+		global $_W;
10
+		global $_GPC;
11
+		$money = str_replace(",", "", $_GPC["money"]);
12
+		$activity = $this->activity($money);
13
+		if( !empty($activity) ) 
14
+		{
15
+			$arr["status"] = "success";
16
+			$arr["did"] = $activity["id"];
17
+			$arr["orderid"] = $_GPC["orderid"];
18
+			echo json_encode($arr);
19
+			exit();
20
+		}
21
+		$arr["status"] = "error";
22
+		$arr["msg"] = "领取失败,请前往订单详情领取!";
23
+		echo json_encode($arr);
24
+		exit();
25
+	}
26
+	public function enjoy() 
27
+	{
28
+		global $_W;
29
+		global $_GPC;
30
+		$openid = $_W["openid"];
31
+		if( !empty($_GPC["sid"]) ) 
32
+		{
33
+			$asql = "SELECT * FROM " . tablename("ewei_shop_sendticket_share") . " WHERE uniacid = " . intval($_W["uniacid"]) . " AND id = " . intval($_GPC["sid"]) . " AND status = 1 AND (expiration = 0 OR (expiration = 1 AND endtime >= " . TIMESTAMP . "))";
34
+			$active = pdo_fetch($asql);
35
+		}
36
+		else 
37
+		{
38
+			$active = $this->activity($_GPC["money"]);
39
+			if( empty($active) ) 
40
+			{
41
+				$this->message("活动已经结束!", mobileUrl("member"));
42
+			}
43
+			$_GPC["sid"] = $active["id"];
44
+		}
45
+		$csql = "SELECT * FROM " . tablename("ewei_shop_coupon_data") . " WHERE uniacid = " . intval($_W["uniacid"]) . " AND shareident = \"" . trim($_GPC["ident"]) . "\" AND openid = \"" . $openid . "\"";
46
+		$clist = pdo_fetchall($csql);
47
+		if( !empty($clist) ) 
48
+		{
49
+			$newCoupon = array( );
50
+		}
51
+		else 
52
+		{
53
+			$insertData = $this->shareSuccess();
54
+			$cpid = array( );
55
+			$nums = array( );
56
+			if( !empty($active["paycpid1"]) ) 
57
+			{
58
+				$cpid[] = $active["paycpid1"];
59
+				$nums[] = $active["paycpnum1"];
60
+			}
61
+			if( !empty($active["paycpid2"]) ) 
62
+			{
63
+				$cpid[] = $active["paycpid2"];
64
+				$nums[] = $active["paycpnum2"];
65
+			}
66
+			if( !empty($active["paycpid3"]) ) 
67
+			{
68
+				$cpid[] = $active["paycpid3"];
69
+				$nums[] = $active["paycpnum3"];
70
+			}
71
+			if( !empty($cpid) ) 
72
+			{
73
+				$newCoupon = array( );
74
+				foreach( $cpid as $ck => $cv ) 
75
+				{
76
+					$couponsql = "SELECT * FROM " . tablename("ewei_shop_coupon") . " WHERE uniacid = " . intval($_W["uniacid"]) . " AND id = " . $cv;
77
+					$newCoupon[$ck] = pdo_fetch($couponsql);
78
+					$newCoupon[$ck]["cpnum"] = $nums[$ck];
79
+				}
80
+			}
81
+			$num = intval(array_sum($nums));
82
+		}
83
+		$storesql = "SELECT * FROM " . tablename("ewei_shop_sysset") . " WHERE uniacid = " . intval($_W["uniacid"]);
84
+		$store = pdo_fetch($storesql);
85
+		$storeInfo = iunserializer($store["sets"]);
86
+		$_W["shopshare"] = array( "title" => $active["sharetitle"], "imgUrl" => (!empty($active["shareicon"]) ? tomedia($active["shareicon"]) : tomedia($storeInfo["shop"]["logo"])), "desc" => (!empty($active["sharedesc"]) ? $active["sharedesc"] : $storeInfo["shop"]["name"]), "link" => mobileUrl("sale/sendticket/share/shareCoupon", array( "openid" => $openid, "sid" => intval($_GPC["sid"]), "ident" => $_GPC["ident"] ), true), "way" => "shareticket()" );
87
+		$firendsql = "SELECT c.backtype,c.deduct,c.backmoney,c.backredpack,c.discount,c.backcredit,d.id as did,d.couponid,d.openid,d.gettime,d.textkey,d.shareident FROM " . tablename("ewei_shop_coupon_data") . " d," . tablename("ewei_shop_coupon") . " c WHERE c.id = d.couponid AND d.uniacid = " . intval($_W["uniacid"]) . " AND d.gettype = 15 AND d.shareident = \"" . trim($_GPC["ident"]) . "\" GROUP BY d.openid ORDER BY d.id ASC limit 20";
88
+		$firendlist = pdo_fetchall($firendsql);
89
+		foreach( $firendlist as $fk => $fv ) 
90
+		{
91
+			$member = m("member")->getMember($fv["openid"]);
92
+			$firendlist[$fk]["headimg"] = $member["avatar"];
93
+			$firendlist[$fk]["nickname"] = $member["nickname"];
94
+			$firendlist[$fk]["text"] = $this->textClause($fv["textkey"]);
95
+		}
96
+		$firendlist = array_reverse($firendlist);
97
+		include($this->template());
98
+	}
99
+	public function activity($money) 
100
+	{
101
+		global $_W;
102
+		$sql = "SELECT * FROM " . tablename("ewei_shop_sendticket_share") . " WHERE uniacid = " . intval($_W["uniacid"]) . " AND status = 1 AND (enough = " . $money . " OR enough <= " . $money . ") AND (expiration = 0 OR (expiration = 1 AND endtime >= " . TIMESTAMP . ")) ORDER BY enough DESC,createtime DESC LIMIT 1";
103
+		$activity = pdo_fetch($sql);
104
+		return $activity;
105
+	}
106
+	public function getCoupon($cpids) 
107
+	{
108
+		global $_W;
109
+		$sql = "SELECT * FROM " . tablename("ewei_shop_coupon") . " WHERE  uniacid = " . intval($_W["uniacid"]) . " AND id IN (" . $cpids . ")";
110
+		$coupon = pdo_fetchall($sql);
111
+		return $coupon;
112
+	}
113
+	public function sendTicket($openid, $couponid, $gettype = 0, $num, $ident = "") 
114
+	{
115
+		global $_W;
116
+		global $_GPC;
117
+		$couponlog = array( "uniacid" => $_W["uniacid"], "openid" => $openid, "logno" => m("common")->createNO("coupon_log", "logno", "CC"), "couponid" => $couponid, "status" => 1, "paystatus" => -1, "creditstatus" => -1, "createtime" => time(), "getfrom" => 3 );
118
+		for( $i = 0; $i < $num; $i++ ) 
119
+		{
120
+			$log = pdo_insert("ewei_shop_coupon_log", $couponlog);
121
+		}
122
+		$tmp = range(0, 20);
123
+		$data = array( "uniacid" => $_W["uniacid"], "openid" => $openid, "couponid" => $couponid, "gettype" => $gettype, "gettime" => time(), "shareident" => $ident );
124
+		for( $i = 0; $i < $num; $i++ ) 
125
+		{
126
+			$data["textkey"] = array_rand($tmp, 1);
127
+			$datas = pdo_insert("ewei_shop_coupon_data", $data);
128
+		}
129
+		if( $log && $datas ) 
130
+		{
131
+			return true;
132
+		}
133
+		return false;
134
+	}
135
+	public function shareCoupon() 
136
+	{
137
+		global $_W;
138
+		global $_GPC;
139
+		$shareurl = $this->curPageURL();
140
+		$shareOpenid = $_GPC["openid"];
141
+		$openid = $_W["openid"];
142
+		if( $shareOpenid == $openid ) 
143
+		{
144
+			$data = array( "isshare" => 1 );
145
+			pdo_update("ewei_shop_order", $data, array( "id" => intval($_GPC["orderid"]) ));
146
+			header("location:" . mobileUrl("sale/sendticket/share/sharePage", array( "shareident" => $_GPC["ident"], "shareurl" => $shareurl )));
147
+			exit();
148
+		}
149
+		$csql = "SELECT * FROM " . tablename("ewei_shop_coupon_data") . " WHERE uniacid = " . intval($_W["uniacid"]) . " AND shareident = \"" . trim($_GPC["ident"]) . "\" AND openid = \"" . $openid . "\"";
150
+		$clist = pdo_fetchall($csql);
151
+		if( !empty($clist) ) 
152
+		{
153
+			header("location:" . mobileUrl("sale/sendticket/share/sharePage", array( "shareident" => $_GPC["ident"] )));
154
+			exit();
155
+		}
156
+		$asql = "SELECT * FROM " . tablename("ewei_shop_sendticket_share") . " WHERE uniacid = " . intval($_W["uniacid"]) . " AND id = " . intval($_GPC["sid"]) . " AND status = 1 AND (expiration = 0 OR (expiration = 1 AND endtime >= " . TIMESTAMP . "))";
157
+		$activity = pdo_fetch($asql);
158
+		if( !empty($activity) ) 
159
+		{
160
+			$cpid = array( );
161
+			$nums = array( );
162
+			if( !empty($activity["sharecpid1"]) ) 
163
+			{
164
+				$cpid[] = $activity["sharecpid1"];
165
+				$nums[] = $activity["sharecpnum1"];
166
+			}
167
+			if( !empty($activity["sharecpid2"]) ) 
168
+			{
169
+				$cpid[] = $activity["sharecpid2"];
170
+				$nums[] = $activity["sharecpnum2"];
171
+			}
172
+			if( !empty($activity["sharecpid3"]) ) 
173
+			{
174
+				$cpid[] = $activity["sharecpid3"];
175
+				$nums[] = $activity["sharecpnum3"];
176
+			}
177
+			foreach( $cpid as $cpks => $cpvs ) 
178
+			{
179
+				$insertid = $this->sendTicket($openid, $cpvs, 15, $nums[$cpks], trim($_GPC["ident"]));
180
+			}
181
+			header("location:" . mobileUrl("sale/sendticket/share/sharePage", array( "shareident" => $_GPC["ident"], "sid" => $_GPC["sid"], "shareurl" => $shareurl )));
182
+			exit();
183
+		}
184
+		else 
185
+		{
186
+			header("location:" . mobileUrl("sale/sendticket/share/sharePage", array( "shareident" => $_GPC["ident"], "close" => 1 )));
187
+			exit();
188
+		}
189
+	}
190
+	public function sharePage() 
191
+	{
192
+		global $_W;
193
+		global $_GPC;
194
+		$openid = $_W["openid"];
195
+		if( $_GPC["close"] == 1 ) 
196
+		{
197
+			$close = 1;
198
+		}
199
+		else 
200
+		{
201
+			$close = 0;
202
+			if( !empty($_GPC["sid"]) ) 
203
+			{
204
+				$asql = "SELECT * FROM " . tablename("ewei_shop_sendticket_share") . " WHERE uniacid = " . intval($_W["uniacid"]) . " AND id = " . intval($_GPC["sid"]) . " AND status = 1 AND (expiration = 0 OR (expiration = 1 AND endtime >= " . TIMESTAMP . "))";
205
+				$activity = pdo_fetch($asql);
206
+				$cpid = array( );
207
+				$nums = array( );
208
+				if( !empty($activity["sharecpid1"]) ) 
209
+				{
210
+					$cpid[] = $activity["sharecpid1"];
211
+					$nums[] = $activity["sharecpnum1"];
212
+				}
213
+				if( !empty($activity["sharecpid2"]) ) 
214
+				{
215
+					$cpid[] = $activity["sharecpid2"];
216
+					$nums[] = $activity["sharecpnum2"];
217
+				}
218
+				if( !empty($activity["sharecpid3"]) ) 
219
+				{
220
+					$cpid[] = $activity["sharecpid3"];
221
+					$nums[] = $activity["sharecpnum3"];
222
+				}
223
+				if( !empty($cpid) ) 
224
+				{
225
+					$newCoupon = array( );
226
+					foreach( $cpid as $ck => $cv ) 
227
+					{
228
+						$couponsql = "SELECT * FROM " . tablename("ewei_shop_coupon") . " WHERE uniacid = " . intval($_W["uniacid"]) . " AND id = " . $cv;
229
+						$newCoupon[$ck] = pdo_fetch($couponsql);
230
+						$newCoupon[$ck]["cpnum"] = $nums[$ck];
231
+					}
232
+				}
233
+				$num = intval(array_sum($nums));
234
+				$storesql = "SELECT * FROM " . tablename("ewei_shop_sysset") . " WHERE uniacid = " . intval($_W["uniacid"]);
235
+				$store = pdo_fetch($storesql);
236
+				$storeInfo = iunserializer($store["sets"]);
237
+				$_W["shopshare"] = array( "title" => $activity["sharetitle"], "imgUrl" => (!empty($activity["shareicon"]) ? tomedia($activity["shareicon"]) : tomedia($storeInfo["shop"]["logo"])), "desc" => (!empty($activity["sharedesc"]) ? $activity["sharedesc"] : $storeInfo["shop"]["name"]), "link" => $_GPC["shareurl"] );
238
+			}
239
+		}
240
+		$firendsql = "SELECT c.backtype,c.deduct,c.backmoney,c.backredpack,c.discount,c.backcredit,d.id as did,d.couponid,d.openid,d.gettime,d.textkey,d.shareident FROM " . tablename("ewei_shop_coupon_data") . " d," . tablename("ewei_shop_coupon") . " c WHERE c.id = d.couponid AND d.uniacid = " . intval($_W["uniacid"]) . " AND d.gettype = 15 AND d.shareident = \"" . trim($_GPC["shareident"]) . "\" GROUP BY d.openid ORDER BY d.id ASC limit 20";
241
+		$firendlist = pdo_fetchall($firendsql);
242
+		foreach( $firendlist as $fk => $fv ) 
243
+		{
244
+			$member = m("member")->getMember($fv["openid"]);
245
+			$firendlist[$fk]["headimg"] = $member["avatar"];
246
+			$firendlist[$fk]["nickname"] = $member["nickname"];
247
+			$firendlist[$fk]["text"] = $this->textClause($fv["textkey"]);
248
+		}
249
+		$firendlist = array_reverse($firendlist);
250
+		include($this->template("sale/sendticket/share/share"));
251
+	}
252
+	public function shareSuccess() 
253
+	{
254
+		global $_W;
255
+		global $_GPC;
256
+		$openid = $_W["openid"];
257
+		$orderSql = "SELECT isshare FROM " . tablename("ewei_shop_order") . " WHERE uniacid = " . intval($_W["uniacid"]) . " AND id = " . intval($_GPC["orderid"]);
258
+		$orderData = pdo_fetch($orderSql);
259
+		if( $orderData["isshare"] == 1 ) 
260
+		{
261
+			return false;
262
+		}
263
+		$couponDataSql = "SELECT * FROM " . tablename("ewei_shop_coupon_data") . " WHERE uniacid = " . intval($_W["uniacid"]) . " AND shareident = \"" . $_GPC["ident"] . "\"";
264
+		$couponData = pdo_fetchall($couponDataSql);
265
+		if( $couponData ) 
266
+		{
267
+			return false;
268
+		}
269
+		$asql = "SELECT * FROM " . tablename("ewei_shop_sendticket_share") . " WHERE uniacid = " . intval($_W["uniacid"]) . " AND id = " . intval($_GPC["sid"]) . " AND status = 1 AND (expiration = 0 OR (expiration = 1 AND endtime >= " . TIMESTAMP . "))";
270
+		$activity = pdo_fetch($asql);
271
+		$cpid = array( );
272
+		$nums = array( );
273
+		if( !empty($activity["paycpid1"]) ) 
274
+		{
275
+			$cpid[] = $activity["paycpid1"];
276
+			$nums[] = $activity["paycpnum1"];
277
+		}
278
+		if( !empty($activity["paycpid2"]) ) 
279
+		{
280
+			$cpid[] = $activity["paycpid2"];
281
+			$nums[] = $activity["paycpnum2"];
282
+		}
283
+		if( !empty($activity["paycpid3"]) ) 
284
+		{
285
+			$cpid[] = $activity["paycpid3"];
286
+			$nums[] = $activity["paycpnum3"];
287
+		}
288
+		$insertid = array( );
289
+		foreach( $cpid as $cpks => $cpvs ) 
290
+		{
291
+			$insertid[] = $this->sendTicket($openid, $cpvs, 15, $nums[$cpks], $_GPC["ident"]);
292
+		}
293
+		$data = array( "isshare" => 1 );
294
+		pdo_update("ewei_shop_order", $data, array( "id" => intval($_GPC["orderid"]) ));
295
+		if( $insertid ) 
296
+		{
297
+			return true;
298
+		}
299
+		return false;
300
+	}
301
+	public function unclaimed() 
302
+	{
303
+		global $_W;
304
+		global $_GPC;
305
+		$openid = $_W["openid"];
306
+		if( !empty($_GPC["sid"]) ) 
307
+		{
308
+			$asql = "SELECT * FROM " . tablename("ewei_shop_sendticket_share") . " WHERE uniacid = " . intval($_W["uniacid"]) . " AND id = " . intval($_GPC["sid"]) . " AND status = 1 AND (expiration = 0 OR (expiration = 1 AND endtime >= " . TIMESTAMP . "))";
309
+			$active = pdo_fetch($asql);
310
+		}
311
+		else 
312
+		{
313
+			$active = $this->activity($_GPC["money"]);
314
+			if( empty($active) ) 
315
+			{
316
+				header("location:" . mobileUrl("sale/sendticket/share/sharePage", array( "shareident" => $_GPC["ident"], "close" => 1 )));
317
+				exit();
318
+			}
319
+			$_GPC["sid"] = $active["id"];
320
+		}
321
+		$cpid = array( );
322
+		$nums = array( );
323
+		if( !empty($active["paycpid1"]) ) 
324
+		{
325
+			$cpid[] = $active["paycpid1"];
326
+			$nums[] = $active["paycpnum1"];
327
+		}
328
+		if( !empty($active["paycpid2"]) ) 
329
+		{
330
+			$cpid[] = $active["paycpid2"];
331
+			$nums[] = $active["paycpnum2"];
332
+		}
333
+		if( !empty($active["paycpid3"]) ) 
334
+		{
335
+			$cpid[] = $active["paycpid3"];
336
+			$nums[] = $active["paycpnum3"];
337
+		}
338
+		if( !empty($cpid) ) 
339
+		{
340
+			$newCoupon = array( );
341
+			foreach( $cpid as $ck => $cv ) 
342
+			{
343
+				$couponsql = "SELECT * FROM " . tablename("ewei_shop_coupon") . " WHERE uniacid = " . intval($_W["uniacid"]) . " AND id = " . $cv;
344
+				$newCoupon[$ck] = pdo_fetch($couponsql);
345
+				$newCoupon[$ck]["cpnum"] = $nums[$ck];
346
+			}
347
+		}
348
+		$num = intval(array_sum($nums));
349
+		$storesql = "SELECT * FROM " . tablename("ewei_shop_sysset") . " WHERE uniacid = " . intval($_W["uniacid"]);
350
+		$store = pdo_fetch($storesql);
351
+		$storeInfo = iunserializer($store["sets"]);
352
+		$ident = "rrsc" . date("Ymd", time()) . intval($_GPC["orderid"]);
353
+		$_W["shopshare"] = array( "title" => $active["sharetitle"], "imgUrl" => (!empty($active["shareicon"]) ? tomedia($active["shareicon"]) : tomedia($storeInfo["shop"]["logo"])), "desc" => (!empty($active["sharedesc"]) ? $active["sharedesc"] : $storeInfo["shop"]["name"]), "link" => mobileUrl("sale/sendticket/share/shareCoupon", array( "openid" => $openid, "sid" => intval($_GPC["sid"]), "ident" => $ident ), true), "way" => "shareticket()" );
354
+		include($this->template());
355
+	}
356
+	public function textClause($key) 
357
+	{
358
+		$text = array( );
359
+		$text[0] = "我是购物狂,我为自己代言!";
360
+		$text[1] = "花钱如尿裤子一般,痛快!";
361
+		$text[2] = "不肯花大钱就买不来贵重东西!";
362
+		$text[3] = "不花钱是造不成宫殿的!";
363
+		$text[4] = "我是购物狂,我在振兴经济!";
364
+		$text[5] = "现在就买,否则晚点会哭!";
365
+		$text[6] = "没有什么比没买的东西叫人念念不忘的!";
366
+		$text[7] = "消费拉动内需,活跃市场!";
367
+		$text[8] = "购物让人心情愉悦!";
368
+		$text[9] = "懂得花钱和懂得挣钱是幸福的!";
369
+		$text[10] = "爱是个银行,不怕花钱,就怕不存钱!";
370
+		$text[11] = "和朋友在一起消费可以促进感情!";
371
+		$text[12] = "向钱看,向厚赚";
372
+		$text[13] = "挣钱是本事,花钱是美德。";
373
+		$text[14] = "会花钱才更会赚钱。";
374
+		$text[15] = "花钱的速度,决定你赚钱的动力。";
375
+		$text[16] = "花了的钱,才是自己的钱。";
376
+		$text[17] = "挣钱、赚钱只有一个目的,就是花!";
377
+		$text[18] = "一个人,富不富,不在于你存了多少,而在于你使用了多少!";
378
+		return $text[$key];
379
+	}
380
+	public function curPageURL() 
381
+	{
382
+		$pageURL = "http";
383
+		if( $_SERVER["HTTPS"] == "on" ) 
384
+		{
385
+			$pageURL .= "s";
386
+		}
387
+		$pageURL .= "://";
388
+		if( $_SERVER["SERVER_PORT"] != "80" ) 
389
+		{
390
+			$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
391
+		}
392
+		else 
393
+		{
394
+			$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
395
+		}
396
+		return $pageURL;
397
+	}
398
+}
399
+?>

+ 100 - 0
addons/ewei_shopv2/core/mobile/shop/category.php Parādīt failu

@@ -0,0 +1,100 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Category_EweiShopV2Page extends MobilePage
7
+{
8
+	public function main()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$merchid = intval($_GPC['merchid']);
13
+		$category_set = $_W['shopset']['category'];
14
+		$category_set['advimg'] = tomedia($category_set['advimg']);
15
+
16
+		if ($category_set['level'] == -1) {
17
+			$this->message('暂时未开启分类', '', 'error');
18
+		}
19
+
20
+		$category = $this->getCategory($category_set['level'], $merchid);
21
+		$set = m('common')->getSysset('category');
22
+		include $this->template();
23
+	}
24
+
25
+	protected function getCategory($level, $merchid = 0)
26
+	{
27
+		$level = intval($level);
28
+		$category = m('shop')->getCategory();
29
+		$category_parent = array();
30
+		$category_children = array();
31
+		$category_grandchildren = array();
32
+
33
+		if (0 < $merchid) {
34
+			$merch_plugin = p('merch');
35
+			$merch_data = m('common')->getPluginset('merch');
36
+			if ($merch_plugin && $merch_data['is_openmerch']) {
37
+				$is_openmerch = 1;
38
+			}
39
+			else {
40
+				$is_openmerch = 0;
41
+			}
42
+
43
+			if ($is_openmerch) {
44
+				$merch_category = $merch_plugin->getSet('merch_category', $merchid);
45
+
46
+				if (!empty($merch_category)) {
47
+					if (!empty($category['parent'])) {
48
+						foreach ($category['parent'] as $key => $value) {
49
+							if (array_key_exists($value['id'], $merch_category)) {
50
+								$category['parent'][$key]['enabled'] = $merch_category[$value['id']];
51
+							}
52
+						}
53
+					}
54
+
55
+					if (!empty($category['children'])) {
56
+						foreach ($category['children'] as $key => $value) {
57
+							if (!empty($value)) {
58
+								foreach ($value as $k => $v) {
59
+									if (array_key_exists($v['id'], $merch_category)) {
60
+										$category['children'][$key][$k]['enabled'] = $merch_category[$v['id']];
61
+									}
62
+								}
63
+							}
64
+						}
65
+					}
66
+				}
67
+			}
68
+		}
69
+
70
+		foreach ($category['parent'] as $value) {
71
+			if ($value['enabled'] == 1) {
72
+				$value['thumb'] = tomedia($value['thumb']);
73
+				$value['advimg'] = tomedia($value['advimg']);
74
+				$category_parent[$value['parentid']][] = $value;
75
+				if (!empty($category['children'][$value['id']]) && 2 <= $level) {
76
+					foreach ($category['children'][$value['id']] as $val) {
77
+						if ($val['enabled'] == 1) {
78
+							$val['thumb'] = tomedia($val['thumb']);
79
+							$val['advimg'] = tomedia($val['advimg']);
80
+							$category_children[$val['parentid']][] = $val;
81
+							if (!empty($category['children'][$val['id']]) && 3 <= $level) {
82
+								foreach ($category['children'][$val['id']] as $v) {
83
+									if ($v['enabled'] == 1) {
84
+										$v['thumb'] = tomedia($v['thumb']);
85
+										$v['advimg'] = tomedia($v['advimg']);
86
+										$category_grandchildren[$v['parentid']][] = $v;
87
+									}
88
+								}
89
+							}
90
+						}
91
+					}
92
+				}
93
+			}
94
+		}
95
+
96
+		return array('parent' => $category_parent, 'children' => $category_children, 'grandchildren' => $category_grandchildren);
97
+	}
98
+}
99
+
100
+?>

+ 29 - 0
addons/ewei_shopv2/core/mobile/shop/cityexpress.php Parādīt failu

@@ -0,0 +1,29 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Cityexpress_EweiShopV2Page extends MobilePage
7
+{
8
+	public function map()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$cityexpress = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_city_express') . ' WHERE uniacid=:uniacid AND merchid=:merchid', array(':uniacid' => $_W['uniacid'], ':merchid' => 0));
13
+		$address = m('common')->getSysset('contact');
14
+		$shop = m('common')->getSysset('shop');
15
+
16
+		if (!empty($address)) {
17
+			$cityexpress['address'] = $address['province'] . $address['city'] . $address['address'];
18
+		}
19
+
20
+		if (!empty($shop)) {
21
+			$cityexpress['name'] = $shop['name'];
22
+			$cityexpress['logo'] = $shop['logo'];
23
+		}
24
+
25
+		include $this->template();
26
+	}
27
+}
28
+
29
+?>

+ 55 - 0
addons/ewei_shopv2/core/mobile/shop/notice.php Parādīt failu

@@ -0,0 +1,55 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Notice_EweiShopV2Page extends MobilePage
7
+{
8
+	public function main()
9
+	{
10
+		global $_W;
11
+		include $this->template();
12
+	}
13
+
14
+	public function get_list()
15
+	{
16
+		global $_W;
17
+		global $_GPC;
18
+		$pindex = max(1, intval($_GPC['page']));
19
+		$psize = 10;
20
+		$condition = ' and `uniacid` = :uniacid and status=1 and iswxapp=0';
21
+		$params = array(':uniacid' => $_W['uniacid']);
22
+		$sql = 'SELECT COUNT(*) FROM ' . tablename('ewei_shop_notice') . (' where 1 ' . $condition);
23
+		$total = pdo_fetchcolumn($sql, $params);
24
+		$sql = 'SELECT * FROM ' . tablename('ewei_shop_notice') . ' where 1 ' . $condition . ' ORDER BY displayorder desc,id desc LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
25
+		$list = pdo_fetchall($sql, $params);
26
+
27
+		foreach ($list as $key => &$row) {
28
+			$row['createtime'] = date('Y-m-d H:i', $row['createtime']);
29
+		}
30
+
31
+		unset($row);
32
+		$list = set_medias($list, 'thumb');
33
+		show_json(1, array('list' => $list, 'pagesize' => $psize, 'total' => $total));
34
+	}
35
+
36
+	public function detail()
37
+	{
38
+		global $_W;
39
+		global $_GPC;
40
+		$id = intval($_GPC['id']);
41
+		$merchid = intval($_GPC['merchid']);
42
+		$merch_plugin = p('merch');
43
+		if ($merch_plugin && !empty($merchid)) {
44
+			$notice = pdo_fetch('select * from ' . tablename('ewei_shop_merch_notice') . ' where id=:id and uniacid=:uniacid and merchid=:merchid and status=1', array(':id' => $id, ':uniacid' => $_W['uniacid'], ':merchid' => $merchid));
45
+		}
46
+		else {
47
+			$notice = pdo_fetch('select * from ' . tablename('ewei_shop_notice') . ' where id=:id and iswxapp=0 and uniacid=:uniacid and status=1', array(':id' => $id, ':uniacid' => $_W['uniacid']));
48
+		}
49
+
50
+		$notice['detail'] = m('ui')->lazy($notice['detail']);
51
+		include $this->template();
52
+	}
53
+}
54
+
55
+?>

+ 68 - 0
addons/ewei_shopv2/core/mobile/store/index.php Parādīt failu

@@ -0,0 +1,68 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Index_EweiShopV2Page extends MobilePage
7
+{
8
+	public function detail()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$id = intval($_GPC['id']);
13
+		$merchid = intval($_GPC['merchid']);
14
+
15
+		if ($merchid) {
16
+			$item = pdo_fetch('select * from ' . tablename('ewei_shop_merch_store') . ' where id =:id and uniacid=:uniacid and merchid=:merchid', array(':id' => $id, ':uniacid' => $_W['uniacid'], 'merchid' => $merchid));
17
+		}
18
+		else {
19
+			$item = pdo_fetch('select * from ' . tablename('ewei_shop_store') . ' where id =:id and uniacid=:uniacid', array(':id' => $id, ':uniacid' => $_W['uniacid']));
20
+		}
21
+
22
+		$item['logo'] = tomedia($item['logo']);
23
+
24
+		if (!empty($item['tag'])) {
25
+			$tags = explode(',', $item['tag']);
26
+
27
+			if (!empty($tags)) {
28
+				foreach ($tags as &$tag) {
29
+					if (2 < mb_strlen($tag, 'UTF-8')) {
30
+						$lable = mb_substr($tag, 0, 2, 'UTF-8');
31
+					}
32
+				}
33
+
34
+				unset($tag);
35
+			}
36
+
37
+			$item['taglist'] = $tags;
38
+			$item['hastag'] = 1;
39
+		}
40
+		else {
41
+			$item['hastag'] = 0;
42
+		}
43
+
44
+		if (!empty($item['label'])) {
45
+			$lables = explode(',', $item['label']);
46
+
47
+			if (!empty($lables)) {
48
+				foreach ($lables as &$lable) {
49
+					if (4 < mb_strlen($lable, 'UTF-8')) {
50
+						$lable = mb_substr($lable, 0, 4, 'UTF-8');
51
+					}
52
+				}
53
+
54
+				unset($lable);
55
+			}
56
+
57
+			$item['labellist'] = $lables;
58
+			$item['haslabel'] = 1;
59
+		}
60
+		else {
61
+			$item['haslabel'] = 0;
62
+		}
63
+
64
+		include $this->template();
65
+	}
66
+}
67
+
68
+?>

+ 42 - 0
addons/ewei_shopv2/core/mobile/store/map.php Parādīt failu

@@ -0,0 +1,42 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Map_EweiShopV2Page extends MobilePage
7
+{
8
+	public function main()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$id = intval($_GPC['id']);
13
+		$merchid = intval($_GPC['merchid']);
14
+
15
+		if (0 < $merchid) {
16
+			$store = pdo_fetch('select * from ' . tablename('ewei_shop_merch_store') . ' where id=:id and uniacid=:uniacid and merchid=:merchid', array(':id' => $id, ':uniacid' => $_W['uniacid'], ':merchid' => $merchid));
17
+		}
18
+		else {
19
+			$store = pdo_fetch('select * from ' . tablename('ewei_shop_store') . ' where id=:id and uniacid=:uniacid', array(':id' => $id, ':uniacid' => $_W['uniacid']));
20
+		}
21
+
22
+		$gcj02 = $this->Convert_BD09_To_GCJ02($store['lat'], $store['lng']);
23
+		$store['lat'] = $gcj02['lat'];
24
+		$store['lng'] = $gcj02['lng'];
25
+		$store['logo'] = empty($store['logo']) ? $_W['shopset']['shop']['logo'] : $store['logo'];
26
+		include $this->template();
27
+	}
28
+
29
+	public function Convert_BD09_To_GCJ02($lat, $lng)
30
+	{
31
+		$x_pi = 3.1415926535897931 * 3000 / 180;
32
+		$x = $lng - 0.0064999999999999997;
33
+		$y = $lat - 0.0060000000000000001;
34
+		$z = sqrt($x * $x + $y * $y) - 2.0000000000000002E-5 * sin($y * $x_pi);
35
+		$theta = atan2($y, $x) - 3.0000000000000001E-6 * cos($x * $x_pi);
36
+		$lng = $z * cos($theta);
37
+		$lat = $z * sin($theta);
38
+		return array('lat' => $lat, 'lng' => $lng);
39
+	}
40
+}
41
+
42
+?>

+ 41 - 0
addons/ewei_shopv2/core/mobile/store/selector.php Parādīt failu

@@ -0,0 +1,41 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Selector_EweiShopV2Page extends MobilePage
7
+{
8
+	public function main()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$ids = trim($_GPC['ids']);
13
+		$type = intval($_GPC['type']);
14
+		$merchid = intval($_GPC['merchid']);
15
+		$condition = '';
16
+
17
+		if (!empty($ids)) {
18
+			$condition = ' and id in(' . $ids . ')';
19
+		}
20
+
21
+		if ($type == 1) {
22
+			$condition .= ' and type in(1,3) ';
23
+		}
24
+		else {
25
+			if ($type == 2) {
26
+				$condition .= ' and type in(2,3) ';
27
+			}
28
+		}
29
+
30
+		if (0 < $merchid) {
31
+			$list = pdo_fetchall('select * from ' . tablename('ewei_shop_merch_store') . ' where  uniacid=:uniacid and merchid=:merchid and status=1 ' . $condition . ' order by displayorder desc,id desc', array(':uniacid' => $_W['uniacid'], ':merchid' => $merchid));
32
+		}
33
+		else {
34
+			$list = pdo_fetchall('select * from ' . tablename('ewei_shop_store') . ' where  uniacid=:uniacid and status=1 ' . $condition . ' order by displayorder desc,id desc', array(':uniacid' => $_W['uniacid']));
35
+		}
36
+
37
+		include $this->template();
38
+	}
39
+}
40
+
41
+?>

+ 13 - 0
addons/ewei_shopv2/core/mobile/util/empty.php Parādīt failu

@@ -0,0 +1,13 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Empty_EweiShopV2Page extends MobilePage
7
+{
8
+	public function main()
9
+	{
10
+	}
11
+}
12
+
13
+?>

+ 14 - 0
addons/ewei_shopv2/core/mobile/util/task.php Parādīt failu

@@ -0,0 +1,14 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Task_EweiShopV2Page extends MobilePage
7
+{
8
+	public function main()
9
+	{
10
+		$this->runTasks();
11
+	}
12
+}
13
+
14
+?>

+ 120 - 0
addons/ewei_shopv2/core/mobile/util/uploader.php Parādīt failu

@@ -0,0 +1,120 @@
1
+<?php  if( !defined("IN_IA") ) 
2
+{
3
+	exit( "Access Denied" );
4
+}
5
+class Uploader_EweiShopV2Page extends MobilePage 
6
+{
7
+	public function main() 
8
+	{
9
+		global $_W;
10
+		global $_GPC;
11
+		load()->func("file");
12
+		$field = $_GPC["file"];
13
+		if( !empty($_FILES[$field]["name"]) ) 
14
+		{
15
+			if( is_array($_FILES[$field]["name"]) ) 
16
+			{
17
+				$files = array( );
18
+				foreach( $_FILES[$field]["name"] as $key => $name ) 
19
+				{
20
+					if( strrchr($name, ".") === false ) 
21
+					{
22
+						$name = $name . ".jpg";
23
+					}
24
+					$file = array( "name" => $name, "type" => $_FILES[$field]["type"][$key], "tmp_name" => $_FILES[$field]["tmp_name"][$key], "error" => $_FILES[$field]["error"][$key], "size" => $_FILES[$field]["size"][$key] );
25
+					if( function_exists("exif_read_data") ) 
26
+					{
27
+						$image = imagecreatefromstring(file_get_contents($file["tmp_name"]));
28
+						$exif = exif_read_data($file["tmp_name"]);
29
+						if( !empty($exif["Orientation"]) ) 
30
+						{
31
+							switch( $exif["Orientation"] ) 
32
+							{
33
+								case 8: $image = imagerotate($image, 90, 0);
34
+								break;
35
+								case 3: $image = imagerotate($image, 180, 0);
36
+								break;
37
+								case 6: $image = imagerotate($image, -90, 0);
38
+								break;
39
+							}
40
+						}
41
+						imagejpeg($image, $file["tmp_name"]);
42
+					}
43
+					$files[] = $this->upload($file);
44
+				}
45
+				$ret = array( "status" => "success", "files" => $files );
46
+				exit( json_encode($ret) );
47
+			}
48
+			else 
49
+			{
50
+				if( strrchr($_FILES[$field]["name"], ".") === false ) 
51
+				{
52
+					$_FILES[$field]["name"] = $_FILES[$field]["name"] . ".jpg";
53
+				}
54
+				$result = $this->upload($_FILES[$field]);
55
+				exit( json_encode($result) );
56
+			}
57
+		}
58
+		else 
59
+		{
60
+			$result["message"] = "请选择要上传的图片!";
61
+			exit( json_encode($result) );
62
+		}
63
+	}
64
+	protected function upload($uploadfile) 
65
+	{
66
+		global $_W;
67
+		global $_GPC;
68
+		$result["status"] = "error";
69
+		if( $uploadfile["error"] != 0 ) 
70
+		{
71
+			$result["message"] = "上传失败,请重试!";
72
+			return $result;
73
+		}
74
+		load()->func("file");
75
+		$path = "/images/ewei_shop/" . $_W["uniacid"];
76
+		if( !is_dir(ATTACHMENT_ROOT . $path) ) 
77
+		{
78
+			mkdirs(ATTACHMENT_ROOT . $path);
79
+		}
80
+		$_W["uploadsetting"] = array( );
81
+		$_W["uploadsetting"]["image"]["folder"] = $path;
82
+		$_W["uploadsetting"]["image"]["extentions"] = $_W["config"]["upload"]["image"]["extentions"];
83
+		$_W["uploadsetting"]["image"]["limit"] = $_W["config"]["upload"]["image"]["limit"];
84
+		$file = file_upload($uploadfile, "image");
85
+		if( is_error($file) ) 
86
+		{
87
+			$result["message"] = $file["message"];
88
+			return $result;
89
+		}
90
+		if( !empty($_W["setting"]["remote"][$_W["uniacid"]]["type"]) ) 
91
+		{
92
+			$_W["setting"]["remote"] = $_W["setting"]["remote"][$_W["uniacid"]];
93
+		}
94
+		if( function_exists("file_remote_upload") ) 
95
+		{
96
+			$remote = file_remote_upload($file["path"]);
97
+			if( is_error($remote) ) 
98
+			{
99
+				$result["message"] = $remote["message"];
100
+				return $result;
101
+			}
102
+		}
103
+		$result["status"] = "success";
104
+		$result["url"] = $file["url"];
105
+		$result["error"] = 0;
106
+		$result["filename"] = $file["path"];
107
+		$result["url"] = tomedia(trim($result["filename"]));
108
+		return $result;
109
+	}
110
+	public function remove() 
111
+	{
112
+		global $_W;
113
+		global $_GPC;
114
+		load()->func("file");
115
+		$file = $_GPC["file"];
116
+		file_delete($file);
117
+		exit( json_encode(array( "status" => "success" )) );
118
+	}
119
+}
120
+?>

+ 158 - 0
addons/ewei_shopv2/core/mobile/verify/index.php Parādīt failu

@@ -0,0 +1,158 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Index_EweiShopV2Page extends MobilePage
7
+{
8
+	public function qrcode()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$orderid = intval($_GPC['id']);
13
+		$verifycode = $_GPC['verifycode'];
14
+		$query = array('id' => $orderid, 'verifycode' => $verifycode);
15
+		$order = pdo_fetch('select istrade from ' . tablename('ewei_shop_order') . ' where id=:id and uniacid=:uniacid limit 1', array(':id' => $orderid, ':uniacid' => $_W['uniacid']));
16
+
17
+		if (empty($order['istrade'])) {
18
+			$url = mobileUrl('verify/detail', $query, true);
19
+		}
20
+		else {
21
+			$url = mobileUrl('verify/tradedetail', $query, true);
22
+		}
23
+
24
+		show_json(1, array('url' => m('qrcode')->createQrcode($url)));
25
+	}
26
+
27
+	public function select()
28
+	{
29
+		global $_W;
30
+		global $_GPC;
31
+		$orderid = intval($_GPC['id']);
32
+		$verifycode = trim($_GPC['verifycode']);
33
+		if (empty($verifycode) || empty($orderid)) {
34
+			show_json(0);
35
+		}
36
+
37
+		$order = pdo_fetch('select id,verifyinfo from ' . tablename('ewei_shop_order') . ' where id=:id and uniacid=:uniacid limit 1', array(':id' => $orderid, ':uniacid' => $_W['uniacid']));
38
+
39
+		if (empty($order)) {
40
+			show_json(0);
41
+		}
42
+
43
+		$verifyinfo = iunserializer($order['verifyinfo']);
44
+
45
+		foreach ($verifyinfo as &$v) {
46
+			if ($v['verifycode'] == $verifycode) {
47
+				if (!empty($v['select'])) {
48
+					$v['select'] = 0;
49
+				}
50
+				else {
51
+					$v['select'] = 1;
52
+				}
53
+			}
54
+		}
55
+
56
+		unset($v);
57
+		pdo_update('ewei_shop_order', array('verifyinfo' => iserializer($verifyinfo)), array('id' => $orderid));
58
+		show_json(1);
59
+	}
60
+
61
+	public function check()
62
+	{
63
+		global $_W;
64
+		global $_GPC;
65
+		$openid = $_W['openid'];
66
+		$uniacid = $_W['uniacid'];
67
+		$orderid = intval($_GPC['id']);
68
+		$order = pdo_fetch('select id,status,isverify,verified from ' . tablename('ewei_shop_order') . ' where id=:id and uniacid=:uniacid and openid=:openid limit 1', array(':id' => $orderid, ':uniacid' => $uniacid, ':openid' => $openid));
69
+
70
+		if (empty($order)) {
71
+			show_json(0);
72
+		}
73
+
74
+		if (empty($order['isverify'])) {
75
+			show_json(0);
76
+		}
77
+
78
+		if ($order['verifytype'] == 0 || $order['verifytype'] == 3) {
79
+			if (empty($order['verified'])) {
80
+				show_json(0);
81
+			}
82
+		}
83
+
84
+		show_json(1);
85
+	}
86
+
87
+	public function detail()
88
+	{
89
+		global $_W;
90
+		global $_GPC;
91
+		$openid = $_W['openid'];
92
+		$uniacid = $_W['uniacid'];
93
+		$orderid = intval($_GPC['id']);
94
+		$data = com('verify')->allow($orderid);
95
+
96
+		if (is_error($data)) {
97
+			$this->message($data['message']);
98
+		}
99
+
100
+		extract($data);
101
+		include $this->template();
102
+	}
103
+
104
+	public function tradedetail()
105
+	{
106
+		global $_W;
107
+		global $_GPC;
108
+		$openid = $_W['openid'];
109
+		$uniacid = $_W['uniacid'];
110
+		$orderid = intval($_GPC['id']);
111
+		$data = com('verify')->allow($orderid);
112
+
113
+		if (is_error($data)) {
114
+			$this->message($data['message']);
115
+		}
116
+
117
+		extract($data);
118
+		$createInfo = array();
119
+		$createInfo['tradestatus'] = $order['tradestatus'];
120
+		$createInfo['betweenprice'] = $order['betweenprice'];
121
+		$newstore_plugin = p('newstore');
122
+		$temp_type = $newstore_plugin->getTempType();
123
+		$tempinfo = $newstore_plugin->getTempInfo($goods['tempid']);
124
+
125
+		if (!empty($goods['peopleid'])) {
126
+			$goods['peopleinfo'] = $newstore_plugin->getPeopleInfo($goods['peopleid']);
127
+		}
128
+
129
+		include $this->template();
130
+	}
131
+
132
+	public function complete()
133
+	{
134
+		global $_W;
135
+		global $_GPC;
136
+		$orderid = intval($_GPC['id']);
137
+		$times = intval($_GPC['times']);
138
+		$data = com('verify')->verify($orderid, $times);
139
+
140
+		if ($data['errno'] == -1) {
141
+			show_json(0, $data['message']);
142
+		}
143
+		else {
144
+			show_json(1);
145
+		}
146
+	}
147
+
148
+	public function success()
149
+	{
150
+		global $_W;
151
+		global $_GPC;
152
+		$id = intval($_GPC['orderid']);
153
+		$times = intval($_GPC['times']);
154
+		$this->message(array('title' => '操作完成', 'message' => '您可以退出浏览器了'), 'javascript:WeixinJSBridge.call("closeWindow");', 'success');
155
+	}
156
+}
157
+
158
+?>

+ 116 - 0
addons/ewei_shopv2/core/mobile/verify/page.php Parādīt failu

@@ -0,0 +1,116 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Page_EweiShopV2Page extends MobilePage
7
+{
8
+	public function main()
9
+	{
10
+		global $_W;
11
+		global $_GPC;
12
+		$openid = $_W['openid'];
13
+		$uniacd = $_W['uniacid'];
14
+		$merchid = 0;
15
+		$merch_plugin = p('merch');
16
+		$saler = pdo_fetch('select * from ' . tablename('ewei_shop_saler') . ' where openid=:openid and uniacid=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':openid' => $openid));
17
+		if (empty($saler) && $merch_plugin) {
18
+			$saler = pdo_fetch('select * from ' . tablename('ewei_shop_merch_saler') . ' where openid=:openid and uniacid=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':openid' => $openid));
19
+		}
20
+
21
+		if (empty($saler)) {
22
+			$this->message('您无核销权限!', 'close');
23
+		}
24
+		else {
25
+			$merchid = $saler['merchid'];
26
+		}
27
+
28
+		if (empty($saler['storeid'])) {
29
+			$this->message('您不属于任何门店,无法进行核销!', 'close');
30
+		}
31
+
32
+		$member = m('member')->getMember($saler['openid']);
33
+		$store = false;
34
+
35
+		if (!empty($saler['storeid'])) {
36
+			if (0 < $merchid) {
37
+				$store = pdo_fetch('select * from ' . tablename('ewei_shop_merch_store') . ' where id=:id and uniacid=:uniacid and merchid = :merchid limit 1', array(':id' => $saler['storeid'], ':uniacid' => $_W['uniacid'], ':merchid' => $merchid));
38
+			}
39
+			else {
40
+				$store = pdo_fetch('select * from ' . tablename('ewei_shop_store') . ' where id=:id and uniacid=:uniacid limit 1', array(':id' => $saler['storeid'], ':uniacid' => $_W['uniacid']));
41
+			}
42
+		}
43
+
44
+		include $this->template();
45
+	}
46
+
47
+	public function search()
48
+	{
49
+		global $_W;
50
+		global $_GPC;
51
+		$verifycode = trim($_GPC['verifycode']);
52
+
53
+		if (empty($verifycode)) {
54
+			show_json(0, '请填写核销码或自提码');
55
+		}
56
+
57
+		if (strlen($verifycode) == 9 && substr($verifycode, 0, 1) == '8') {
58
+			$verifygood = m('verifygoods')->search($verifycode);
59
+
60
+			if (is_error($verifygood)) {
61
+				show_json(0, $verifygood['message']);
62
+			}
63
+
64
+			show_json(1, array('verifygoodid' => $verifygood['id'], 'verifycode' => $verifycode, 'isverifygoods' => 1));
65
+		}
66
+		else {
67
+			$orderid = pdo_fetchcolumn('select id from ' . tablename('ewei_shop_order') . ' where uniacid=:uniacid and ( verifycode=:verifycode or verifycodes like :verifycodes ) limit 1 ', array(':uniacid' => $_W['uniacid'], ':verifycode' => $verifycode, ':verifycodes' => '%|' . $verifycode . '|%'));
68
+
69
+			if (empty($orderid)) {
70
+				show_json(0, '未查询到订单,请核对');
71
+			}
72
+
73
+			$allow = com('verify')->allow($orderid);
74
+
75
+			if (is_error($allow)) {
76
+				show_json(0, $allow['message']);
77
+			}
78
+
79
+			extract($allow);
80
+			$verifyinfo = iunserializer($order['verifyinfo']);
81
+
82
+			if ($order['verifytype'] == 2) {
83
+				foreach ($verifyinfo as &$v) {
84
+					unset($v['select']);
85
+
86
+					if ($v['verifycode'] == $verifycode) {
87
+						if ($v['verified']) {
88
+							show_json(0, '此消费码已经使用!');
89
+						}
90
+
91
+						$v['select'] = 1;
92
+					}
93
+				}
94
+
95
+				unset($v);
96
+				pdo_update('ewei_shop_order', array('verifyinfo' => iserializer($verifyinfo)), array('id' => $orderid));
97
+			}
98
+
99
+			show_json(1, array('orderid' => $orderid, 'istrade' => intval($order['istrade']), 'isverifygoods' => 0));
100
+		}
101
+	}
102
+
103
+	public function complete()
104
+	{
105
+		global $_W;
106
+		global $_GPC;
107
+		$openid = $_W['openid'];
108
+		$uniacid = $_W['uniacid'];
109
+		$orderid = intval($_GPC['id']);
110
+		$times = intval($_GPC['times']);
111
+		com('verify')->verify($orderid, $times);
112
+		show_json(1);
113
+	}
114
+}
115
+
116
+?>

+ 147 - 0
addons/ewei_shopv2/core/mobile/verify/verifygoods.php Parādīt failu

@@ -0,0 +1,147 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+	exit('Access Denied');
4
+}
5
+
6
+class Verifygoods_EweiShopV2Page extends MobilePage
7
+{
8
+	/**
9
+     * 会员核销卡核销页面
10
+     */
11
+	public function detail()
12
+	{
13
+		global $_W;
14
+		global $_GPC;
15
+		$openid = $_W['openid'];
16
+		$verifycode = trim($_GPC['verifycode']);
17
+		$id = trim($_GPC['id']);
18
+
19
+		if (empty($verifycode)) {
20
+			$this->message('未查询到记次时商品或核销码已失效,请核对核销码!', '', 'error');
21
+		}
22
+
23
+		$item = pdo_fetch('select vg.*,g.id as goodsid ,g.title,g.subtitle,g.thumb,vg.storeid  from ' . tablename('ewei_shop_verifygoods') . "   vg\r\n\t\t inner join " . tablename('ewei_shop_order_goods') . " og on vg.ordergoodsid = og.id\r\n\t\t inner join " . tablename('ewei_shop_goods') . " g on og.goodsid = g.id\r\n\t\t where  vg.id =:id and  vg.verifycode=:verifycode and vg.uniacid=:uniacid and vg.invalid =0 limit 1", array(':id' => $id, ':uniacid' => $_W['uniacid'], ':verifycode' => $verifycode));
24
+
25
+		if (empty($item)) {
26
+			$this->message('未查询到记次时商品或核销码已失效,请核对核销码!', '', 'error');
27
+		}
28
+
29
+		if (intval($item['codeinvalidtime']) < time()) {
30
+			$this->message('核销码已失效,请联系用户刷新页面获取最新核销码!', '', 'error');
31
+		}
32
+
33
+		$saler = pdo_fetch('select * from ' . tablename('ewei_shop_saler') . ' where  status=1  and openid=:openid and uniacid=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':openid' => $openid));
34
+
35
+		if (empty($saler)) {
36
+			$this->message('您不是核销员,无权核销', '', 'error');
37
+		}
38
+
39
+		$store = pdo_fetch('select * from ' . tablename('ewei_shop_store') . ' where id=:id and uniacid=:uniacid limit 1', array(':id' => $saler['storeid'], ':uniacid' => $_W['uniacid']));
40
+		if (!empty($item['storeid']) && !empty($store) && $item['storeid'] != $store['id']) {
41
+			$this->message('该商品无法在您所属门店核销!请重新确认!', '', 'error');
42
+		}
43
+
44
+		if (!empty($item['limitnum'])) {
45
+			$verifygoodlogs = pdo_fetchall('select *  from ' . tablename('ewei_shop_verifygoods_log') . '    where verifygoodsid =:id  ', array(':id' => $item['id']));
46
+			$verifynum = 0;
47
+
48
+			foreach ($verifygoodlogs as $verifygoodlog) {
49
+				$verifynum += intval($verifygoodlog['verifynum']);
50
+			}
51
+
52
+			$lastverifys = intval($item['limitnum']) - $verifynum;
53
+		}
54
+
55
+		if (empty($item['limittype'])) {
56
+			$limitdate = intval($item['starttime']) + intval($item['limitdays']) * 86400;
57
+		}
58
+		else {
59
+			$limitdate = intval($item['limitdate']);
60
+		}
61
+
62
+		if ($limitdate < time()) {
63
+			$this->message('该商品已过期!', '', 'error');
64
+		}
65
+
66
+		$termofvalidity = date('Y-m-d H:i', $limitdate);
67
+		include $this->template();
68
+	}
69
+
70
+	/**
71
+     * 记计核销台
72
+     */
73
+	public function main()
74
+	{
75
+		global $_W;
76
+		global $_GPC;
77
+		$openid = $_W['openid'];
78
+		$saler = pdo_fetch('select * from ' . tablename('ewei_shop_saler') . ' where status=1  and openid=:openid and uniacid=:uniacid limit 1', array(':uniacid' => $_W['uniacid'], ':openid' => $openid));
79
+
80
+		if (empty($saler)) {
81
+			$this->message('您无核销权限!', 'close');
82
+		}
83
+
84
+		$member = m('member')->getMember($saler['openid']);
85
+		$store = false;
86
+
87
+		if (!empty($saler['storeid'])) {
88
+			$store = pdo_fetch('select * from ' . tablename('ewei_shop_store') . ' where id=:id and uniacid=:uniacid limit 1', array(':id' => $saler['storeid'], ':uniacid' => $_W['uniacid']));
89
+		}
90
+
91
+		include $this->template();
92
+	}
93
+
94
+	/**
95
+     * 查看核销
96
+     */
97
+	public function search()
98
+	{
99
+		global $_W;
100
+		global $_GPC;
101
+		$openid = $_W['openid'];
102
+		$verifycode = trim($_GPC['verifycode']);
103
+
104
+		if (empty($verifycode)) {
105
+			show_json(0, '请填写核销码');
106
+		}
107
+
108
+		$verifygood = m('verifygoods')->search($verifycode);
109
+
110
+		if (is_error($verifygood)) {
111
+			show_json(0, $verifygood['message']);
112
+		}
113
+
114
+		show_json(1, array('verifygoodid' => $verifygood['id']));
115
+	}
116
+
117
+	/**
118
+     * 完成核销
119
+     */
120
+	public function complete()
121
+	{
122
+		global $_W;
123
+		global $_GPC;
124
+		$times = intval($_GPC['times']);
125
+		$verifycode = trim($_GPC['verifycode']);
126
+		$remarks = trim($_GPC['remarks']);
127
+		$result = m('verifygoods')->complete($verifycode, $times, $remarks);
128
+
129
+		if (is_error($result)) {
130
+			show_json(0, $result['message']);
131
+		}
132
+
133
+		show_json(1, array('verifygoodid' => $result['verifygoodid'], 'orderid' => $result['orderid']));
134
+	}
135
+
136
+	/**
137
+     * 核销成功页面
138
+     */
139
+	public function success()
140
+	{
141
+		global $_W;
142
+		global $_GPC;
143
+		$this->message(array('title' => '操作完成', 'message' => '您可以退出浏览器了'), 'javascript:WeixinJSBridge.call("closeWindow");', 'success');
144
+	}
145
+}
146
+
147
+?>

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1021 - 0
addons/ewei_shopv2/core/mobile/verify/verifyorder.php


+ 431 - 0
addons/ewei_shopv2/core/mobile/verifygoods/index.php Parādīt failu

@@ -0,0 +1,431 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+    exit('Access Denied');
4
+}
5
+
6
+class Index_EweiShopV2Page extends MobilePage {
7
+
8
+    function main() {
9
+        global $_W, $_GPC;
10
+        $openid = $_W['openid'];
11
+        $uniacid = $_W['uniacid'];
12
+
13
+        /*$verifygoods = pdo_fetchall('select vg.*,g.title,g.subtitle,g.thumb  from ' . tablename('ewei_shop_verifygoods') . '   vg
14
+         inner join ' . tablename('ewei_shop_order_goods') . ' og on vg.ordergoodsid = og.id
15
+         inner join ' . tablename('ewei_shop_goods') . ' g on og.goodsid = g.id
16
+         left  join ' . tablename('ewei_shop_order') . ' o on vg.orderid = o.id
17
+         left  join ' . tablename('ewei_shop_order_refund') . ' orf on o.refundid = orf.id
18
+         where   vg.uniacid=:uniacid and vg.openid=:openid and vg.invalid =0 and (orf.status is null or orf.status=0)', array(':uniacid' => $uniacid,':openid' => $openid));*/
19
+
20
+
21
+
22
+        include $this->template();
23
+    }
24
+
25
+
26
+    function getlist(){
27
+        global $_W, $_GPC;
28
+
29
+        $openid = $_W['openid'];
30
+
31
+        $cate = trim($_GPC['cate']);
32
+        if(!empty($cate)){
33
+            if($cate=='used'){
34
+                $used = 1;
35
+            }else{
36
+                $past = 1;
37
+            }
38
+        }
39
+
40
+        $pindex = max(1, intval($_GPC['page']));
41
+        $psize = 10;
42
+
43
+
44
+        $time = time();
45
+
46
+        $sql='select vg.*,g.title,g.subtitle,g.thumb,c.card_id  from ' . tablename('ewei_shop_verifygoods') . '   vg
47
+		 inner join ' . tablename('ewei_shop_order_goods') . ' og on vg.ordergoodsid = og.id
48
+		 left  join ' . tablename('ewei_shop_order') . ' o on vg.orderid = o.id
49
+		 left  join ' . tablename('ewei_shop_order_refund') . ' orf on o.refundid = orf.id
50
+		 inner join ' . tablename('ewei_shop_goods') . ' g on og.goodsid = g.id
51
+		 left  join ' . tablename('ewei_shop_goods_cards') . ' c on c.id = g.cardid
52
+		 where   vg.uniacid=:uniacid and vg.openid=:openid and vg.invalid =0 and (o.refundid=0 or orf.status<0) and o.status>0';
53
+
54
+        if(!empty($past)){
55
+            $sql.=" and  ((vg.limittype=0   and vg.limitdays * 86400 + vg.starttime <{$time} )or ( vg.limittype=1   and vg.limitdate <{$time} )) and vg.used < 1";
56
+        }
57
+        else if(!empty($used)){
58
+            $sql.=" and vg.used =1";
59
+        }else if(empty($used)){
60
+            $sql.=" and   ((vg.limittype=0   and vg.limitdays * 86400 + vg.starttime >={$time} )or ( vg.limittype=1   and vg.limitdate >={$time} ))  and  vg.used =0  ";
61
+        }
62
+
63
+        $total = pdo_fetchcolumn($sql, array(':uniacid' =>  $_W['uniacid'],':openid' => $openid));
64
+        $sql.=" order by vg.starttime desc  LIMIT " . ($pindex - 1) * $psize . ',' . $psize; //类型+最低消费+示使用
65
+        $verifygoods = set_medias(pdo_fetchall($sql, array(':uniacid' =>  $_W['uniacid'],':openid' => $openid)), 'thumb');
66
+
67
+
68
+        if(empty($verifygoods))
69
+        {
70
+            $verifygoods=array();
71
+        }
72
+
73
+        foreach ($verifygoods as $i=>&$row) {
74
+            $verifygoodlogs = pdo_fetchall('select *  from ' . tablename('ewei_shop_verifygoods_log') . '    where verifygoodsid =:id  ', array(':id' => $row['id']));
75
+
76
+            $verifynum = 0;
77
+
78
+            foreach($verifygoodlogs as $verifygoodlog)
79
+            {
80
+                $verifynum +=intval($verifygoodlog['verifynum']);
81
+            }
82
+
83
+            $row['numlimit']=0;
84
+
85
+            if(empty($row['limitnum']))
86
+            {
87
+                if(empty($row['limittype']))
88
+                {
89
+                    $surplusdays = (intval($row['starttime']) +  $row['limitdays']*86400 -time())/86400;
90
+
91
+                }else
92
+                {
93
+                    $surplusdays = (intval($row['limitdate'])-time())/86400;
94
+                }
95
+
96
+                if($surplusdays>0)
97
+                {
98
+                    $row['surplusnum'] = intval($surplusdays);
99
+                }else
100
+                {
101
+                    $row['surplusnum'] = "<span style='font-size: 1rem'>已过期</span>";
102
+                    $row['expired'] = 1;
103
+                }
104
+
105
+            }else
106
+            {
107
+                $row['numlimit']=1;
108
+                $num = intval($row['limitnum']) - $verifynum;
109
+                if($num>0)
110
+                {
111
+                    $row['surplusnum'] = $num;
112
+                }else
113
+                {
114
+                    $row['surplusnum'] = "<span style='font-size: 1rem'>已使用</span>";
115
+                }
116
+            }
117
+
118
+
119
+
120
+            if(empty($row['limittype']))
121
+            {
122
+                $row['termofvalidity']  =date('Y-m-d H:i',  intval($row['starttime']) +  $row['limitdays']*86400  );
123
+            }else
124
+            {
125
+                $row['termofvalidity'] = date('Y-m-d H:i',  $row['limitdate']);
126
+            }
127
+
128
+            if(empty($cate)){
129
+                $row['canuse']=1;
130
+            }
131
+
132
+            if(is_weixin())
133
+            {
134
+                if(!empty($row['card_id'])&&empty($row['activecard']))
135
+                {
136
+                    $row['cangetcard']=1;
137
+                }
138
+            }
139
+
140
+            //如果是已过期的
141
+            if(!empty($past)){
142
+                $row['expired'] = 1;
143
+            }
144
+
145
+        }
146
+
147
+        unset($row);
148
+
149
+
150
+        show_json(1,array('list'=>$verifygoods,'pagesize'=>$psize, 'total'=>$total));
151
+    }
152
+
153
+    function detail() {
154
+
155
+        global $_W, $_GPC;
156
+        $openid = $_W['openid'];
157
+        $uniacid = $_W['uniacid'];
158
+        $cansee = 1;
159
+
160
+        if(!empty($_GPC['card_id'])&&!empty($_GPC['encrypt_code'])&&!empty($_GPC['openid']))
161
+        {
162
+
163
+            if($openid!=$_GPC['openid']){
164
+                header('location: ' . mobileUrl('verifygoods'));
165
+            }
166
+
167
+            $card_id = $_GPC['card_id'];
168
+            $encrypt_code = $_GPC['encrypt_code'];
169
+            //$data = com('wxcard')->wxCardCodeDecrypt($encrypt_code);
170
+            $data =com_run('wxcard::wxCardCodeDecrypt',$encrypt_code);
171
+            if(empty($data) || is_wxerror($data))
172
+            {
173
+                header('location: ' . mobileUrl('verifygoods'));
174
+            }
175
+
176
+            $code = $data['code'];
177
+
178
+            $item = pdo_fetch('select vg.*,g.title,g.subtitle,g.thumb  from ' . tablename('ewei_shop_verifygoods') . '   vg
179
+		 inner join ' . tablename('ewei_shop_order_goods') . ' og on vg.ordergoodsid = og.id
180
+		 left  join ' . tablename('ewei_shop_order') . ' o on vg.orderid = o.id
181
+		 left  join ' . tablename('ewei_shop_order_refund') . ' orf on o.refundid = orf.id
182
+		 inner join ' . tablename('ewei_shop_goods') . ' g on og.goodsid = g.id
183
+		 inner  join ' . tablename('ewei_shop_goods_cards') . ' c on c.id = g.cardid
184
+		 where   vg.uniacid=:uniacid and vg.openid=:openid and vg.invalid =0  and c.card_id =:card_id and vg.cardcode=:cardcode and (o.refundid=0 or orf.status<0) and o.status>0  limit 1',
185
+                array(':uniacid' => $uniacid,':openid' => $openid,":card_id"=>$card_id,":cardcode"=>$code));
186
+
187
+            if(empty($item))
188
+            {
189
+                header('location: ' . mobileUrl('verifygoods'));
190
+            }
191
+            $id = $item['id'];
192
+        }
193
+        else
194
+        {
195
+
196
+            $id = $_GPC['id'];
197
+
198
+            $item = pdo_fetch('select vg.*,g.title,g.subtitle,g.thumb  from ' . tablename('ewei_shop_verifygoods') . '   vg
199
+		 inner join ' . tablename('ewei_shop_order_goods') . ' og on vg.ordergoodsid = og.id
200
+		 left  join ' . tablename('ewei_shop_order') . ' o on vg.orderid = o.id
201
+		 left  join ' . tablename('ewei_shop_order_refund') . ' orf on o.refundid = orf.id
202
+		 inner join ' . tablename('ewei_shop_goods') . ' g on og.goodsid = g.id
203
+		 where  vg.id =:id and vg.uniacid=:uniacid and vg.openid=:openid and vg.invalid =0 and (o.refundid=0 or orf.status<0) and o.status>0 limit 1', array(':id' => $id,':uniacid' => $uniacid,':openid' => $openid));
204
+        }
205
+
206
+
207
+        if(empty($item))
208
+        {
209
+            header('location: ' . mobileUrl('verifygoods'));
210
+        }
211
+
212
+        //判断时间是否过期
213
+        if(empty($item['limittype']))
214
+        {
215
+            $limitdate = intval($item['starttime']) +  intval($item['limitdays'])*86400;
216
+        }
217
+        else
218
+        {
219
+            $limitdate = intval($item['limitdate']);
220
+        }
221
+
222
+        if($limitdate<time())
223
+        {
224
+//			header('location: ' . mobileUrl('verifygoods'));
225
+            $cansee = 2;
226
+        }
227
+
228
+        $limitdatestr = date('Y-m-d H:i',  $limitdate);
229
+
230
+
231
+        $verifygoodlogs = pdo_fetchall('select vgl.*,s.storename,sa.salername  from ' . tablename('ewei_shop_verifygoods_log') . '   vgl
232
+		left  join ' . tablename('ewei_shop_store') . ' s on s.id = vgl.storeid
233
+		left  join ' . tablename('ewei_shop_saler') . ' sa on sa.id = vgl.salerid
234
+          where  vgl.verifygoodsid =:id order by vgl.verifydate desc ', array(':id' => $id));
235
+
236
+        $verifynum = 0;
237
+
238
+        foreach($verifygoodlogs as &$verifygoodlog)
239
+        {
240
+            if(empty($verifygoodlog['storename'])){
241
+                $verifygoodlog['storename'] = $_W['shopset']['shop']['name'];
242
+            }
243
+            $verifynum +=intval($verifygoodlog['verifynum']);
244
+        }
245
+        unset($verifygoodlog);
246
+
247
+
248
+        if(!empty($item['limitnum']))
249
+        {
250
+            if($verifynum>=intval($item['limitnum']))
251
+            {
252
+//				header('location: ' . mobileUrl('verifygoods'));
253
+                $cansee = 3;
254
+            }
255
+        }
256
+        if($item['used'] ==1){
257
+            $cansee = 3;
258
+        }
259
+        $verifycode = $item['verifycode'];
260
+
261
+        if(empty($verifycode)||$item['codeinvalidtime']<time())
262
+        {
263
+            //记次时商品核销码8开头加8位随机数,共9位
264
+            $verifycode = "8".random(8, true);
265
+
266
+            while (1) {
267
+                $count = pdo_fetchcolumn('select count(*) from ' . tablename('ewei_shop_verifygoods') . ' where verifycode=:verifycode and uniacid=:uniacid limit 1', array(':verifycode' => $verifycode, ':uniacid' => $_W['uniacid']));
268
+                if ($count <= 0) {
269
+                    break;
270
+                }
271
+                $verifycode = random(8, true);
272
+            }
273
+
274
+            $data = array(
275
+                "verifycode"=>$verifycode,
276
+                "codeinvalidtime"=>time()+1800
277
+            );
278
+
279
+            pdo_update("ewei_shop_verifygoods",$data,array("id"=>$item['id']));
280
+
281
+
282
+        }
283
+
284
+        $query = array('id' => $item['id'],'verifycode'=>$verifycode);
285
+        $url = mobileUrl('verify/verifygoods/detail', $query, true);
286
+        $qrurl = m('qrcode')->createQrcode($url);
287
+
288
+        if(strlen($verifycode)==8)
289
+        {
290
+            $verifycode= substr($verifycode,0,4)." ".substr($verifycode,4,4);
291
+        }
292
+        else if(strlen($verifycode)==9)
293
+        {
294
+            $verifycode= substr($verifycode,0,3)." ".substr($verifycode,3,3)." ".substr($verifycode,6,3);
295
+        }
296
+
297
+        $goodsstore = pdo_fetch('select * from ' . tablename('ewei_shop_store') . ' where id=:id and uniacid=:uniacid limit 1', array(':id' => $item['storeid'], ':uniacid' => $_W['uniacid']));
298
+
299
+        include $this->template();
300
+    }
301
+
302
+
303
+    function activecard()
304
+    {
305
+        global $_W, $_GPC;
306
+        $openid = $_W['openid'];
307
+        $card_id = $_GPC['card_id'];
308
+        $encrypt_code = $_GPC['encrypt_code'];
309
+        $code = "";
310
+
311
+        if(empty($card_id)||empty($encrypt_code))
312
+        {
313
+        }
314
+
315
+        //$data = com('wxcard')->wxCardCodeDecrypt($encrypt_code);
316
+        $data =com_run('wxcard::wxCardCodeDecrypt',$encrypt_code);
317
+
318
+        if(empty($data) || is_wxerror($data))
319
+        {
320
+
321
+            $this->message(array("message"=>"激活链接错误!", "title"=>"激活链接错误!", "buttondisplay"=>true), mobileUrl('verifygoods'), 'error');
322
+        }
323
+
324
+        $code = $data['code'];
325
+
326
+        $sql='select vg.*,g.title,g.subtitle,g.thumb,c.card_id  from ' . tablename('ewei_shop_verifygoods') . '   vg
327
+		 inner join ' . tablename('ewei_shop_order_goods') . ' og on vg.ordergoodsid = og.id
328
+		 inner join ' . tablename('ewei_shop_goods') . ' g on og.goodsid = g.id
329
+		 left  join ' . tablename('ewei_shop_goods_cards') . ' c on c.id = g.cardid
330
+		 where   vg.uniacid=:uniacid and vg.openid=:openid and vg.invalid =0
331
+		 and ((vg.limittype=0   and vg.limitdays * 86400 + vg.starttime >=unix_timestamp() )or ( vg.limittype=1   and vg.limitdate >=unix_timestamp() ))  and  vg.used =0  and (vg.activecard=0 or vg.activecard is null) and g.cardid>0  and c.card_id=:card_id';
332
+
333
+        $verifygoods = set_medias(pdo_fetchall($sql, array(':uniacid' =>  $_W['uniacid'],':openid' => $openid,':card_id'=>$card_id)), 'thumb');
334
+
335
+
336
+        if(empty($verifygoods))
337
+        {
338
+            //$good =com('wxcard')->getgoodidbycardid($card_id);
339
+            $good =com_run('wxcard::getgoodidbycardid',$card_id);
340
+
341
+            if(empty($good))
342
+            {
343
+                $this->message(array("message"=>"激活链接错误!", "title"=>"激活链接错误!", "buttondisplay"=>true), mobileUrl('verifygoods'), 'error');
344
+            }else
345
+            {
346
+                $this->message(array("message"=>"请先购买此商品!", "title"=>"请先购买此商品!", "buttondisplay"=>true),mobileUrl('goods/detail',array('id'=>$good['id'])), '');
347
+                //header('location: ' . mobileUrl('goods/detail',array('id'=>$good['id'])));
348
+            }
349
+        }
350
+
351
+        foreach ($verifygoods as $i=>&$row) {
352
+            $verifygoodlogs = pdo_fetchall('select *  from ' . tablename('ewei_shop_verifygoods_log') . '    where verifygoodsid =:id  ', array(':id' => $row['id']));
353
+
354
+            $verifynum = 0;
355
+
356
+            foreach($verifygoodlogs as $verifygoodlog)
357
+            {
358
+                $verifynum +=intval($verifygoodlog['verifynum']);
359
+            }
360
+
361
+            if(empty($row['limitnum']))
362
+            {
363
+                $row['surplusnum'] = "不限";
364
+            }else
365
+            {
366
+                $num = intval($row['limitnum']) - $verifynum;
367
+                $row['surplusnum'] = $num."次";
368
+            }
369
+
370
+            if(empty($row['limittype']))
371
+            {
372
+                $row['termofvalidity']  =date('Y-m-d H:i',  intval($row['starttime']) +  $row['limitdays']*86400  );
373
+            }else
374
+            {
375
+                $row['termofvalidity'] = date('Y-m-d H:i',  $row['limitdate']);
376
+            }
377
+
378
+            if(!empty($row['card_id'])&&empty($row['getcard']))
379
+            {
380
+                $row['cangetcard']=1;
381
+            }
382
+        }
383
+
384
+        unset($row);
385
+
386
+        include $this->template();
387
+
388
+    }
389
+
390
+    function active()
391
+    {
392
+        global $_W, $_GPC;
393
+        $openid = $_W['openid'];
394
+        $card_id = $_GPC['card_id'];
395
+        $encrypt_code = $_GPC['encrypt_code'];
396
+        $code = "";
397
+
398
+        $id = $_GPC['id'];
399
+
400
+        if(empty($card_id)||empty($encrypt_code)||empty($id))
401
+        {
402
+            $this->message(array("message"=>"激活链接错误!", "title"=>"激活链接错误!", "buttondisplay"=>true), mobileUrl('verifygoods'), 'error');
403
+        }
404
+
405
+        //$data = com('wxcard')->wxCardCodeDecrypt($encrypt_code);
406
+        $data =com_run('wxcard::wxCardCodeDecrypt',$encrypt_code);
407
+
408
+        if(empty($data) || is_wxerror($data))
409
+        {
410
+
411
+            $this->message(array("message"=>"激活链接错误!", "title"=>"激活链接错误!", "buttondisplay"=>true), mobileUrl('verifygoods'), 'error');
412
+        }
413
+
414
+        $code = $data['code'];
415
+
416
+
417
+        //$result =com('wxcard')->ActivateVerifygoodCard($id,$card_id,$code,$openid);
418
+        $result =com_run('wxcard::ActivateVerifygoodCard',$id,$card_id,$code,$openid);
419
+
420
+
421
+        if($result)
422
+        {
423
+            $redirect = mobileUrl('verifygoods/detail',array('id'=>$id));
424
+
425
+            $this->message(array("message"=>"您的核销卡已成功激活!", "title"=>"激活成功!", "buttondisplay"=>true), $redirect, 'success');
426
+        }else
427
+        {
428
+            $this->message(array("message"=>"激活链接错误!", "title"=>"激活链接错误!", "buttondisplay"=>true), mobileUrl('verifygoods'), 'error');
429
+        }
430
+    }
431
+}

+ 88 - 0
addons/ewei_shopv2/core/model/account.php Parādīt failu

@@ -0,0 +1,88 @@
1
+<?php
2
+class Account_EweiShopV2Model
3
+{
4
+	public function checkLogin()
5
+	{
6
+		global $_W;
7
+		global $_GPC;
8
+
9
+		if (empty($_W['openid'])) {
10
+			$openid = $this->checkOpenid();
11
+
12
+			if (!empty($openid)) {
13
+				return $openid;
14
+			}
15
+
16
+			$url = urlencode(base64_encode($_SERVER['QUERY_STRING']));
17
+			$loginurl = mobileUrl('account/login', array('mid' => $_GPC['mid'], 'backurl' => $_W['isajax'] ? '' : $url));
18
+
19
+			if ($_W['isajax']) {
20
+				show_json(0, array('url' => $loginurl, 'message' => '请先登录!'));
21
+			}
22
+
23
+			header('location: ' . $loginurl);
24
+			exit();
25
+		}
26
+	}
27
+
28
+	public function checkOpenid()
29
+	{
30
+		global $_W;
31
+		global $_GPC;
32
+		$key = '__ewei_shopv2_member_session_' . $_W['uniacid'];
33
+
34
+		if (isset($_GPC[$key])) {
35
+			$session = json_decode(base64_decode($_GPC[$key]), true);
36
+
37
+			if (is_array($session)) {
38
+				$member = m('member')->getMember($session['openid']);
39
+				if (is_array($member) && $session['ewei_shopv2_member_hash'] == md5($member['pwd'] . $member['salt'])) {
40
+					$GLOBALS['_W']['ewei_shopv2_member_hash'] = md5($member['pwd'] . $member['salt']);
41
+					$GLOBALS['_W']['ewei_shopv2_member'] = $member;
42
+					return $member['openid'];
43
+				}
44
+
45
+				isetcookie($key, false, -100);
46
+			}
47
+		}
48
+	}
49
+
50
+	public function setLogin($member)
51
+	{
52
+		global $_W;
53
+
54
+		if (!is_array($member)) {
55
+			$member = m('member')->getMember($member);
56
+		}
57
+
58
+		if (!empty($member)) {
59
+			$member['ewei_shopv2_member_hash'] = md5($member['pwd'] . $member['salt']);
60
+			$key = '__ewei_shopv2_member_session_' . $_W['uniacid'];
61
+			$cookie = base64_encode(json_encode($member));
62
+			isetcookie($key, $cookie, 7 * 86400);
63
+		}
64
+	}
65
+
66
+	public function getSalt()
67
+	{
68
+		$salt = random(16);
69
+
70
+		while (1) {
71
+			$count = pdo_fetchcolumn('select count(*) from ' . tablename('ewei_shop_member') . ' where salt=:salt limit 1', array(':salt' => $salt));
72
+
73
+			if ($count <= 0) {
74
+				break;
75
+			}
76
+
77
+			$salt = random(16);
78
+		}
79
+
80
+		return $salt;
81
+	}
82
+}
83
+
84
+if (!defined('IN_IA')) {
85
+	exit('Access Denied');
86
+}
87
+
88
+?>

+ 595 - 0
addons/ewei_shopv2/core/model/bind.php Parādīt failu

@@ -0,0 +1,595 @@
1
+<?php
2
+class Bind_EweiShopV2Model
3
+{
4
+	/**
5
+     * @param array $member
6
+     * @return bool
7
+     */
8
+	public function iswxm($member = array())
9
+	{
10
+		if (empty($member) || !is_array($member)) {
11
+			return true;
12
+		}
13
+
14
+		if (strexists($member['openid'], 'sns_wx_') || strexists($member['openid'], 'sns_qq_') || strexists($member['openid'], 'sns_wa_') || strexists($member['openid'], 'wap_user_')) {
15
+			return false;
16
+		}
17
+
18
+		return true;
19
+	}
20
+
21
+	/**
22
+     * @param int $mid
23
+     * @param array $arr
24
+     */
25
+	public function update($mid = 0, $arr = array())
26
+	{
27
+		global $_W;
28
+		if (empty($mid) || empty($arr) || !is_array($arr)) {
29
+			return NULL;
30
+		}
31
+
32
+		pdo_update('ewei_shop_member', $arr, array('id' => $mid, 'uniacid' => $_W['uniacid']));
33
+	}
34
+
35
+	/**
36
+     * @param array $a
37
+     * @param array $b
38
+     * @return array
39
+     */
40
+	public function merge($a = array(), $b = array())
41
+	{
42
+		global $_W;
43
+		if (empty($a) || empty($b) || $a['id'] == $b['id']) {
44
+			return error(0, 'params error');
45
+		}
46
+
47
+		$createtime = $b['createtime'] < $a['createtime'] ? $b['createtime'] : $a['createtime'];
48
+		$childtime = $b['childtime'] < $a['childtime'] ? $b['childtime'] : $a['childtime'];
49
+		$comparelevel = m('member')->compareLevel(array($a['level'], $b['level']));
50
+		$level = $comparelevel ? $b['level'] : $a['level'];
51
+		$isblack = !empty($a['isblack']) || !empty($b['isblack']) ? 1 : 0;
52
+		$openid_qq = !empty($b['openid_qq']) && empty($a['openid_qq']) ? $b['openid_qq'] : $a['openid_qq'];
53
+		$openid_wx = !empty($b['openid_wx']) && empty($a['openid_wx']) ? $b['openid_wx'] : $a['openid_wx'];
54
+		$openid_wa = !empty($b['openid_wa']) && empty($a['openid_wa']) ? $b['openid_wa'] : $a['openid_wa'];
55
+		if (!empty($a['isagent']) && empty($b['isagent'])) {
56
+			$isagent = 1;
57
+			$agentid = $a['agentid'];
58
+			$status = !empty($a['status']) ? 1 : 0;
59
+			$agenttime = $a['agenttime'];
60
+			$agentlevel = $a['agentlevel'];
61
+			$agentblack = $a['agentblack'];
62
+			$fixagentid = $a['fixagentid'];
63
+		}
64
+		else {
65
+			if (!empty($b['isagent']) && empty($a['isagent'])) {
66
+				$isagent = 1;
67
+				$agentid = $b['agentid'];
68
+				$status = !empty($b['status']) ? 1 : 0;
69
+				$agenttime = $b['agenttime'];
70
+				$agentlevel = $b['agentlevel'];
71
+				$agentblack = $b['agentblack'];
72
+				$fixagentid = $b['fixagentid'];
73
+			}
74
+			else {
75
+				if (!empty($b['isagent']) && !empty($a['isagent'])) {
76
+					$compare = p('commission')->compareLevel(array($a['agentlevel'], $b['agentlevel']));
77
+					$isagent = 1;
78
+
79
+					if ($compare) {
80
+						$agentid = $b['agentid'];
81
+						if (empty($b['agentid']) && !empty($a['agentid'])) {
82
+							$agentid = $a['agentid'];
83
+						}
84
+
85
+						$status = !empty($b['status']) ? 1 : 0;
86
+						$agentblack = !empty($b['agentblack']) ? 1 : 0;
87
+						$fixagentid = !empty($b['fixagentid']) ? 1 : 0;
88
+					}
89
+					else {
90
+						$agentid = $a['agentid'];
91
+						if (empty($a['agentid']) && !empty($b['agentid'])) {
92
+							$agentid = $b['agentid'];
93
+						}
94
+
95
+						$status = !empty($a['status']) ? 1 : 0;
96
+						$agentblack = !empty($a['agentblack']) ? 1 : 0;
97
+						$fixagentid = !empty($a['fixagentid']) ? 1 : 0;
98
+					}
99
+
100
+					$agenttime = $compare ? $b['agenttime'] : $a['agenttime'];
101
+					$agentlevel = $compare ? $b['agentlevel'] : $a['agentlevel'];
102
+				}
103
+				else {
104
+					if (empty($b['isagent']) && empty($a['isagent'])) {
105
+						if (!empty($a['agentid']) && !empty($b['agentid'])) {
106
+							$agentid = $a['agentid'];
107
+						}
108
+						else {
109
+							if (empty($a['agentid']) && !empty($b['agentid'])) {
110
+								$agentid = $b['agentid'];
111
+							}
112
+							else {
113
+								if (!empty($a['agentid']) && empty($b['agentid'])) {
114
+									$agentid = $a['agentid'];
115
+								}
116
+							}
117
+						}
118
+
119
+						if (!empty($a['inviter']) && !empty($b['inviter'])) {
120
+							$inviter = $a['inviter'];
121
+						}
122
+						else {
123
+							if (empty($a['inviter']) && !empty($b['inviter'])) {
124
+								$inviter = $b['inviter'];
125
+							}
126
+							else {
127
+								if (!empty($a['inviter']) && empty($b['inviter'])) {
128
+									$inviter = $a['inviter'];
129
+								}
130
+							}
131
+						}
132
+					}
133
+				}
134
+			}
135
+		}
136
+
137
+		if (!empty($a['isauthor']) && empty($b['isauthor'])) {
138
+			$isauthor = $a['isauthor'];
139
+			$authorstatus = !empty($a['authorstatus']) ? 1 : 0;
140
+			$authortime = $a['authortime'];
141
+			$authorlevel = $a['authorlevel'];
142
+			$authorblack = $a['authorblack'];
143
+		}
144
+		else {
145
+			if (!empty($b['isauthor']) && empty($a['isauthor'])) {
146
+				$isauthor = $b['isauthor'];
147
+				$authorstatus = !empty($b['authorstatus']) ? 1 : 0;
148
+				$authortime = $b['authortime'];
149
+				$authorlevel = $b['authorlevel'];
150
+				$authorblack = $b['authorblack'];
151
+			}
152
+			else {
153
+				if (!empty($b['isauthor']) && !empty($a['isauthor'])) {
154
+					return error(0, '此手机号已绑定另一用户(a1)<br>请联系管理员');
155
+				}
156
+			}
157
+		}
158
+
159
+		if (!empty($a['ispartner']) && empty($b['ispartner'])) {
160
+			$ispartner = 1;
161
+			$partnerstatus = !empty($a['partnerstatus']) ? 1 : 0;
162
+			$partnertime = $a['partnertime'];
163
+			$partnerlevel = $a['partnerlevel'];
164
+			$partnerblack = $a['partnerblack'];
165
+		}
166
+		else {
167
+			if (!empty($b['ispartner']) && empty($a['ispartner'])) {
168
+				$ispartner = 1;
169
+				$partnerstatus = !empty($b['partnerstatus']) ? 1 : 0;
170
+				$partnertime = $b['partnertime'];
171
+				$partnerlevel = $b['partnerlevel'];
172
+				$partnerblack = $b['partnerblack'];
173
+			}
174
+			else {
175
+				if (!empty($b['ispartner']) && !empty($a['ispartner'])) {
176
+					return error(0, '此手机号已绑定另一用户(p)<br>请联系管理员');
177
+				}
178
+			}
179
+		}
180
+
181
+		if (!empty($a['isaagent']) && empty($b['isaagent'])) {
182
+			$isaagent = $a['isaagent'];
183
+			$aagentstatus = !empty($a['aagentstatus']) ? 1 : 0;
184
+			$aagenttime = $a['aagenttime'];
185
+			$aagentlevel = $a['aagentlevel'];
186
+			$aagenttype = $a['aagenttype'];
187
+			$aagentprovinces = $a['aagentprovinces'];
188
+			$aagentcitys = $a['aagentcitys'];
189
+			$aagentareas = $a['aagentareas'];
190
+		}
191
+		else {
192
+			if (!empty($b['isaagent']) && empty($a['isaagent'])) {
193
+				$isaagent = $b['isaagent'];
194
+				$aagentstatus = !empty($b['aagentstatus']) ? 1 : 0;
195
+				$aagenttime = $b['aagenttime'];
196
+				$aagentlevel = $b['aagentlevel'];
197
+				$aagenttype = $b['aagenttype'];
198
+				$aagentprovinces = $b['aagentprovinces'];
199
+				$aagentcitys = $b['aagentcitys'];
200
+				$aagentareas = $b['aagentareas'];
201
+			}
202
+			else {
203
+				if (!empty($b['isaagent']) && !empty($a['isaagent'])) {
204
+					return error(0, '此手机号已绑定另一用户(a2)<br>请联系管理员');
205
+				}
206
+			}
207
+		}
208
+
209
+		$arr = array();
210
+
211
+		if (isset($createtime)) {
212
+			$arr['createtime'] = $createtime;
213
+		}
214
+
215
+		if (isset($childtime)) {
216
+			$arr['childtime'] = $childtime;
217
+		}
218
+
219
+		if (isset($level)) {
220
+			$arr['level'] = $level;
221
+		}
222
+
223
+		if (isset($groupid)) {
224
+			$arr['groupid'] = $groupid;
225
+		}
226
+
227
+		if (isset($isblack)) {
228
+			$arr['isblack'] = $isblack;
229
+		}
230
+
231
+		if (isset($openid_qq)) {
232
+			$arr['openid_qq'] = $openid_qq;
233
+		}
234
+
235
+		if (isset($openid_wx)) {
236
+			$arr['openid_wx'] = $openid_wx;
237
+		}
238
+
239
+		if (isset($openid_wa)) {
240
+			$arr['openid_wa'] = $openid_wa;
241
+		}
242
+
243
+		if (isset($status)) {
244
+			$arr['status'] = $status;
245
+		}
246
+
247
+		if (isset($isagent)) {
248
+			$arr['isagent'] = $isagent;
249
+		}
250
+
251
+		if (isset($agentid)) {
252
+			$arr['agentid'] = $agentid;
253
+		}
254
+
255
+		if (isset($agenttime)) {
256
+			$arr['agenttime'] = $agenttime;
257
+		}
258
+
259
+		if (isset($agentlevel)) {
260
+			$arr['agentlevel'] = $agentlevel;
261
+		}
262
+
263
+		if (isset($agentblack)) {
264
+			$arr['agentblack'] = $agentblack;
265
+		}
266
+
267
+		if (isset($fixagentid)) {
268
+			$arr['fixagentid'] = $fixagentid;
269
+		}
270
+
271
+		if (isset($isauthor)) {
272
+			$arr['isauthor'] = $isauthor;
273
+		}
274
+
275
+		if (isset($authorstatus)) {
276
+			$arr['authorstatus'] = $authorstatus;
277
+		}
278
+
279
+		if (isset($authortime)) {
280
+			$arr['authortime'] = $authortime;
281
+		}
282
+
283
+		if (isset($authorlevel)) {
284
+			$arr['authorlevel'] = $authorlevel;
285
+		}
286
+
287
+		if (isset($authorblack)) {
288
+			$arr['authorblack'] = $authorblack;
289
+		}
290
+
291
+		if (isset($ispartner)) {
292
+			$arr['ispartner'] = $ispartner;
293
+		}
294
+
295
+		if (isset($partnerstatus)) {
296
+			$arr['partnerstatus'] = $partnerstatus;
297
+		}
298
+
299
+		if (isset($partnertime)) {
300
+			$arr['partnertime'] = $partnertime;
301
+		}
302
+
303
+		if (isset($partnerlevel)) {
304
+			$arr['partnerlevel'] = $partnerlevel;
305
+		}
306
+
307
+		if (isset($partnerblack)) {
308
+			$arr['partnerblack'] = $partnerblack;
309
+		}
310
+
311
+		if (isset($isaagent)) {
312
+			$arr['isaagent'] = $isaagent;
313
+		}
314
+
315
+		if (isset($aagentstatus)) {
316
+			$arr['aagentstatus'] = $aagentstatus;
317
+		}
318
+
319
+		if (isset($aagenttime)) {
320
+			$arr['aagenttime'] = $aagenttime;
321
+		}
322
+
323
+		if (isset($aagentlevel)) {
324
+			$arr['aagentlevel'] = $aagentlevel;
325
+		}
326
+
327
+		if (isset($aagenttype)) {
328
+			$arr['aagenttype'] = $aagenttype;
329
+		}
330
+
331
+		if (isset($aagentprovinces)) {
332
+			$arr['aagentprovinces'] = $aagentprovinces;
333
+		}
334
+
335
+		if (isset($aagentcitys)) {
336
+			$arr['aagentcitys'] = $aagentcitys;
337
+		}
338
+
339
+		if (isset($aagentareas)) {
340
+			$arr['aagentareas'] = $aagentareas;
341
+		}
342
+
343
+		if (isset($inviter)) {
344
+			$arr['inviter'] = $inviter;
345
+		}
346
+
347
+		if (!empty($arr) && is_array($arr)) {
348
+			pdo_update('ewei_shop_member', $arr, array('id' => $b['id']));
349
+		}
350
+
351
+		pdo_update('ewei_shop_commission_apply', array('mid' => $b['id']), array('uniacid' => $_W['uniacid'], 'mid' => $a['id']));
352
+		pdo_update('ewei_shop_order', array('agentid' => $b['id']), array('agentid' => $a['id']));
353
+		pdo_update('ewei_shop_member', array('agentid' => $b['id']), array('agentid' => $a['id']));
354
+		$mergeinfo = ' 合并前用户: ' . $a['nickname'] . '(' . $a['id'] . ') 合并后用户: ' . $b['nickname'] . '(' . $b['id'] . ')';
355
+
356
+		if (0 < $a['credit1']) {
357
+			m('member')->setCredit($b['openid'], 'credit1', abs($a['credit1']), '全网通会员数据合并增加积分 +' . $a['credit1'] . $mergeinfo);
358
+		}
359
+
360
+		if (0 < $a['credit2']) {
361
+			m('member')->setCredit($b['openid'], 'credit2', abs($a['credit2']), '全网通会员数据合并增加余额 +' . $a['credit2'] . $mergeinfo);
362
+		}
363
+
364
+		pdo_delete('ewei_shop_member', array('id' => $a['id'], 'uniacid' => $_W['uniacid']));
365
+
366
+		if (method_exists(m('member'), 'memberRadisCountDelete')) {
367
+			m('member')->memberRadisCountDelete();
368
+		}
369
+
370
+		$tables = pdo_fetchall('SHOW TABLES like \'%_ewei_shop_%\'');
371
+
372
+		foreach ($tables as $k => $v) {
373
+			$v = array_values($v);
374
+			$tablename = str_replace($_W['config']['db']['tablepre'], '', $v[0]);
375
+			if (pdo_fieldexists($tablename, 'openid') && pdo_fieldexists($tablename, 'uniacid')) {
376
+				pdo_update($tablename, array('openid' => $b['openid']), array('uniacid' => $_W['uniacid'], 'openid' => $a['openid']));
377
+			}
378
+
379
+			if (pdo_fieldexists($tablename, 'openid') && pdo_fieldexists($tablename, 'acid')) {
380
+				pdo_update($tablename, array('openid' => $b['openid']), array('acid' => $_W['acid'], 'openid' => $a['openid']));
381
+			}
382
+
383
+			if (pdo_fieldexists($tablename, 'mid') && pdo_fieldexists($tablename, 'uniacid')) {
384
+				pdo_update($tablename, array('mid' => $b['id']), array('uniacid' => $_W['uniacid'], 'mid' => $a['id']));
385
+			}
386
+		}
387
+
388
+		$c = m('member')->getMember($b['openid']);
389
+		pdo_insert('ewei_shop_member_mergelog', array('uniacid' => $_W['uniacid'], 'mergetime' => time(), 'openid_a' => $a['openid'], 'openid_b' => $b['openid'], 'mid_a' => $a['id'], 'mid_b' => $b['id'], 'detail_a' => iserializer($a), 'detail_b' => iserializer($b), 'detail_c' => iserializer($c)));
390
+		return error(1);
391
+	}
392
+
393
+	/**
394
+     * 绑定送积分
395
+     * @param array $member
396
+     */
397
+	public function sendCredit($member = array())
398
+	{
399
+		if (empty($member)) {
400
+			return NULL;
401
+		}
402
+
403
+		$data = m('common')->getPluginset('sale');
404
+		if (!empty($data['bindmobile']) && 0 < intval($data['bindmobilecredit'])) {
405
+			m('member')->setCredit($member['openid'], 'credit1', abs($data['bindmobilecredit']), '绑定手机号送积分 +' . $data['bindmobilecredit']);
406
+		}
407
+	}
408
+
409
+	/**
410
+     * 数据迁移
411
+     * @param array $a
412
+     * @param array $b
413
+     * @return array
414
+     */
415
+	public function mergeforuniacid($a = array(), $b = array())
416
+	{
417
+		global $_W;
418
+		if (empty($a) || empty($b) || $a['id'] == $b['id']) {
419
+			return error(0, 'params error');
420
+		}
421
+
422
+		if (!empty($b['mobileverify'])) {
423
+			return error(0, 'params error');
424
+		}
425
+
426
+		$createtime = $b['createtime'] < $a['createtime'] ? $b['createtime'] : $a['createtime'];
427
+		$childtime = $b['childtime'] < $a['childtime'] ? $b['childtime'] : $a['childtime'];
428
+		$comparelevel = m('member')->compareLevel(array($a['level'], $b['level']));
429
+		$level = $comparelevel ? $b['level'] : $a['level'];
430
+		$isblack = !empty($a['isblack']) || !empty($b['isblack']) ? 1 : 0;
431
+		$openid_qq = !empty($b['openid_qq']) && empty($a['openid_qq']) ? $b['openid_qq'] : $a['openid_qq'];
432
+		$openid_wx = !empty($b['openid_wx']) && empty($a['openid_wx']) ? $b['openid_wx'] : $a['openid_wx'];
433
+		$openid_wa = !empty($b['openid_wa']) && empty($a['openid_wa']) ? $b['openid_wa'] : $a['openid_wa'];
434
+		if (!empty($a['isagent']) && empty($b['isagent'])) {
435
+			$isagent = 1;
436
+			$agentid = $a['agentid'];
437
+			$status = !empty($a['status']) ? 1 : 0;
438
+			$agenttime = $a['agenttime'];
439
+			$agentlevel = $a['agentlevel'];
440
+			$agentblack = $a['agentblack'];
441
+			$fixagentid = $a['fixagentid'];
442
+		}
443
+		else {
444
+			if (!empty($b['isagent']) && empty($a['isagent'])) {
445
+				$isagent = 1;
446
+				$agentid = $b['agentid'];
447
+				$status = !empty($b['status']) ? 1 : 0;
448
+				$agenttime = $b['agenttime'];
449
+				$agentlevel = $b['agentlevel'];
450
+				$agentblack = $b['agentblack'];
451
+				$fixagentid = $b['fixagentid'];
452
+			}
453
+			else {
454
+				if (!empty($b['isagent']) && !empty($a['isagent'])) {
455
+					$compare = p('commission')->compareLevel(array($a['agentlevel'], $b['agentlevel']));
456
+					$isagent = 1;
457
+
458
+					if ($compare) {
459
+						$agentid = $b['agentid'];
460
+						if (empty($b['agentid']) && !empty($a['agentid'])) {
461
+							$agentid = $a['agentid'];
462
+						}
463
+
464
+						$status = !empty($b['status']) ? 1 : 0;
465
+						$agentblack = !empty($b['agentblack']) ? 1 : 0;
466
+						$fixagentid = !empty($b['fixagentid']) ? 1 : 0;
467
+					}
468
+					else {
469
+						$agentid = $a['agentid'];
470
+						if ($a['agentid'] && !empty($b['agentid'])) {
471
+							$agentid = $b['agentid'];
472
+						}
473
+
474
+						$status = !empty($a['status']) ? 1 : 0;
475
+						$agentblack = !empty($a['agentblack']) ? 1 : 0;
476
+						$fixagentid = !empty($a['fixagentid']) ? 1 : 0;
477
+					}
478
+
479
+					$agenttime = $compare ? $b['agenttime'] : $a['agenttime'];
480
+					$agentlevel = $compare ? $b['agentlevel'] : $a['agentlevel'];
481
+				}
482
+			}
483
+		}
484
+
485
+		$arr = array();
486
+		$arr['ishb'] = 1;
487
+
488
+		if (isset($createtime)) {
489
+			$arr['createtime'] = $createtime;
490
+		}
491
+
492
+		if (isset($childtime)) {
493
+			$arr['childtime'] = $childtime;
494
+		}
495
+
496
+		if (isset($level)) {
497
+			$arr['level'] = $level;
498
+		}
499
+
500
+		if (isset($groupid)) {
501
+			$arr['groupid'] = $groupid;
502
+		}
503
+
504
+		if (isset($isblack)) {
505
+			$arr['isblack'] = $isblack;
506
+		}
507
+
508
+		if (isset($openid_qq)) {
509
+			$arr['openid_qq'] = $openid_qq;
510
+		}
511
+
512
+		if (isset($openid_wx)) {
513
+			$arr['openid_wx'] = $openid_wx;
514
+		}
515
+
516
+		if (isset($openid_wa)) {
517
+			$arr['openid_wa'] = $openid_wa;
518
+		}
519
+
520
+		if (isset($status)) {
521
+			$arr['status'] = $status;
522
+		}
523
+
524
+		if (isset($isagent)) {
525
+			$arr['isagent'] = $isagent;
526
+		}
527
+
528
+		if (isset($agentid)) {
529
+			$arr['agentid'] = $agentid;
530
+		}
531
+
532
+		if (isset($agenttime)) {
533
+			$arr['agenttime'] = $agenttime;
534
+		}
535
+
536
+		if (isset($agentlevel)) {
537
+			$arr['agentlevel'] = $agentlevel;
538
+		}
539
+
540
+		if (isset($agentblack)) {
541
+			$arr['agentblack'] = $agentblack;
542
+		}
543
+
544
+		if (isset($fixagentid)) {
545
+			$arr['fixagentid'] = $fixagentid;
546
+		}
547
+
548
+		if (!empty($arr) && is_array($arr)) {
549
+			pdo_update('ewei_shop_member', $arr, array('id' => $b['id']));
550
+		}
551
+
552
+		pdo_update('ewei_shop_commission_apply', array('mid' => $b['id']), array('mid' => $a['id']));
553
+		pdo_update('ewei_shop_order', array('agentid' => $b['id']), array('agentid' => $a['id']));
554
+		pdo_update('ewei_shop_member', array('agentid' => $b['id']), array('agentid' => $a['id']));
555
+		$mergeinfo = ' 合并前用户: ' . $a['nickname'] . '(' . $a['id'] . ') 合并后用户: ' . $b['nickname'] . '(' . $b['id'] . ')';
556
+
557
+		if (0 < $a['credit1']) {
558
+			m('member')->setCredit($b['openid'], 'credit1', abs($a['credit1']), '数据迁移会员数据合并增加积分 +' . $a['credit1'] . $mergeinfo);
559
+		}
560
+
561
+		if (0 < $a['credit2']) {
562
+			m('member')->setCredit($b['openid'], 'credit2', abs($a['credit2']), '数据迁移会员数据合并增加余额 +' . $a['credit2'] . $mergeinfo);
563
+		}
564
+
565
+		$tables = pdo_fetchall('SHOW TABLES like \'%_ewei_shop_%\'');
566
+
567
+		foreach ($tables as $k => $v) {
568
+			$v = array_values($v);
569
+			$tablename = str_replace($_W['config']['db']['tablepre'], '', $v[0]);
570
+			if (pdo_fieldexists($tablename, 'openid') && pdo_fieldexists($tablename, 'uniacid')) {
571
+				if ($tablename != 'ewei_shop_member') {
572
+					pdo_update($tablename, array('openid' => $b['openid']), array('uniacid' => $_W['uniacid'], 'openid' => $a['openid']));
573
+				}
574
+			}
575
+
576
+			if (pdo_fieldexists($tablename, 'openid') && pdo_fieldexists($tablename, 'acid')) {
577
+				pdo_update($tablename, array('openid' => $b['openid']), array('acid' => $_W['acid'], 'openid' => $a['openid']));
578
+			}
579
+
580
+			if (pdo_fieldexists($tablename, 'mid') && pdo_fieldexists($tablename, 'uniacid')) {
581
+				pdo_update($tablename, array('mid' => $b['id']), array('uniacid' => $_W['uniacid'], 'mid' => $a['id']));
582
+			}
583
+		}
584
+
585
+		$c = m('member')->getMember($b['openid']);
586
+		pdo_insert('ewei_shop_member_mergelog', array('uniacid' => $_W['uniacid'], 'fromuniacid' => $_W['uniacid'], 'mergetime' => time(), 'openid_a' => $a['openid'], 'openid_b' => $b['openid'], 'mid_a' => $a['id'], 'mid_b' => $b['id'], 'detail_a' => iserializer($a), 'detail_b' => iserializer($b), 'detail_c' => iserializer($c)));
587
+		return error(1);
588
+	}
589
+}
590
+
591
+if (!defined('IN_IA')) {
592
+	exit('Access Denied');
593
+}
594
+
595
+?>

+ 146 - 0
addons/ewei_shopv2/core/model/cache.php Parādīt failu

@@ -0,0 +1,146 @@
1
+<?php
2
+class Cache_EweiShopV2Model
3
+{
4
+	public function get_key($key = '', $uniacid = '')
5
+	{
6
+		global $_W;
7
+		static $APPID;
8
+		static $_uniacid;
9
+		$account_key = '';
10
+		$isme = $uniacid == $_W['uniacid'] || empty($uniacid);
11
+
12
+		if ($isme) {
13
+			$uniacid = $_W['uniacid'];
14
+			$account_key = $_W['account']['key'];
15
+		}
16
+
17
+		if (function_exists('redis')) {
18
+			$redis = redis();
19
+
20
+			if (!is_error($redis)) {
21
+				if (stripos($uniacid, 'global') !== false) {
22
+					return 'ewei_shopv2_syscache_' . $_W['setting']['site']['key'] . '_global_' . $key;
23
+				}
24
+
25
+				if (empty($account_key)) {
26
+					if ($isme) {
27
+						if (is_null($APPID) || empty($APPID) || $_uniacid != $uniacid) {
28
+							$_uniacid = $uniacid;
29
+							$APPID = pdo_fetchcolumn('SELECT `key` FROM ' . tablename('account_wechats') . ' WHERE uniacid=:uniacid', array(':uniacid' => $uniacid));
30
+						}
31
+
32
+						$account_key = $APPID;
33
+					}
34
+					else {
35
+						$account_key = pdo_fetchcolumn('SELECT `key` FROM ' . tablename('account_wechats') . ' WHERE uniacid=:uniacid', array(':uniacid' => $uniacid));
36
+					}
37
+				}
38
+
39
+				return 'ewei_shopv2_syscache_' . $_W['setting']['site']['key'] . '_' . $uniacid . '_' . $account_key . '_' . $key;
40
+			}
41
+		}
42
+
43
+		return EWEI_SHOPV2_PREFIX . md5($uniacid . '_new_' . $key);
44
+	}
45
+
46
+	public function getArray($key = '', $uniacid = '')
47
+	{
48
+		return $this->get($key, $uniacid);
49
+	}
50
+
51
+	public function getString($key = '', $uniacid = '')
52
+	{
53
+		return $this->get($key, $uniacid);
54
+	}
55
+
56
+	public function get($key = '', $uniacid = '')
57
+	{
58
+		global $_W;
59
+
60
+		if (function_exists('redis')) {
61
+			$redis = redis();
62
+
63
+			if (!is_error($redis)) {
64
+				$prefix = '__iserializer__format__::';
65
+				$value = $redis->get($this->get_key($key, $uniacid));
66
+
67
+				if (empty($value)) {
68
+					return false;
69
+				}
70
+
71
+				if (stripos($value, $prefix) === 0) {
72
+					$ret = iunserializer(substr($value, strlen($prefix)));
73
+
74
+					foreach ($ret as $k => &$v) {
75
+						if (is_serialized($v)) {
76
+							$v = iunserializer($v);
77
+						}
78
+
79
+						if (is_array($v)) {
80
+							foreach ($v as $k1 => &$v1) {
81
+								if (is_serialized($v1)) {
82
+									$v1 = iunserializer($v1);
83
+								}
84
+							}
85
+
86
+							unset($v1);
87
+						}
88
+					}
89
+
90
+					return $ret;
91
+				}
92
+
93
+				return $value;
94
+			}
95
+		}
96
+
97
+		return cache_read($this->get_key($key, $uniacid));
98
+	}
99
+
100
+	public function set($key = '', $value = NULL, $uniacid = '')
101
+	{
102
+		if (function_exists('redis')) {
103
+			$redis = redis();
104
+
105
+			if (!is_error($redis)) {
106
+				$prefix = '__iserializer__format__::';
107
+
108
+				if (is_array($value)) {
109
+					foreach ($value as $k => &$v) {
110
+						if (is_serialized($v)) {
111
+							$v = iunserializer($v);
112
+						}
113
+					}
114
+
115
+					unset($v);
116
+					$value = $prefix . iserializer($value);
117
+				}
118
+
119
+				$redis->set($this->get_key($key, $uniacid), $value);
120
+				return NULL;
121
+			}
122
+		}
123
+
124
+		cache_write($this->get_key($key, $uniacid), $value);
125
+	}
126
+
127
+	public function del($key, $uniacid = '')
128
+	{
129
+		if (function_exists('redis')) {
130
+			$redis = redis();
131
+
132
+			if (!is_error($redis)) {
133
+				$redis->del($this->get_key($key, $uniacid));
134
+				return NULL;
135
+			}
136
+		}
137
+
138
+		cache_delete($this->get_key($key, $uniacid));
139
+	}
140
+}
141
+
142
+if (!defined('IN_IA')) {
143
+	exit('Access Denied');
144
+}
145
+
146
+?>

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1784 - 0
addons/ewei_shopv2/core/model/common.php


+ 31 - 0
addons/ewei_shopv2/core/model/cookie.php Parādīt failu

@@ -0,0 +1,31 @@
1
+<?php
2
+class Cookie_EweiShopV2Model
3
+{
4
+	private $prefix;
5
+
6
+	public function __construct()
7
+	{
8
+		global $_W;
9
+		$this->prefix = EWEI_SHOPV2_PREFIX . '_cookie_' . $_W['uniacid'] . '_';
10
+	}
11
+
12
+	public function set($key, $value)
13
+	{
14
+		setcookie($this->prefix . $key, iserializer($value), time() + 3600 * 24 * 365);
15
+	}
16
+
17
+	public function get($key)
18
+	{
19
+		if (!isset($_COOKIE[$this->prefix . $key])) {
20
+			return false;
21
+		}
22
+
23
+		return iunserializer($_COOKIE[$this->prefix . $key]);
24
+	}
25
+}
26
+
27
+if (!defined('IN_IA')) {
28
+	exit('Access Denied');
29
+}
30
+
31
+?>

+ 281 - 0
addons/ewei_shopv2/core/model/dispatch.php Parādīt failu

@@ -0,0 +1,281 @@
1
+<?php  if( !defined("IN_IA") ) 
2
+{
3
+	exit( "Access Denied" );
4
+}
5
+class Dispatch_EweiShopV2Model 
6
+{
7
+	public function getDispatchPrice($param, $d, $calculatetype = -1) 
8
+	{
9
+		if( empty($d) ) 
10
+		{
11
+			return 0;
12
+		}
13
+		$price = 0;
14
+		if( $calculatetype == -1 ) 
15
+		{
16
+			$calculatetype = $d["calculatetype"];
17
+		}
18
+		if( $calculatetype == 1 ) 
19
+		{
20
+			if( $param <= $d["firstnum"] ) 
21
+			{
22
+				$price = floatval($d["firstnumprice"]);
23
+			}
24
+			else 
25
+			{
26
+				$price = floatval($d["firstnumprice"]);
27
+				$secondweight = $param - floatval($d["firstnum"]);
28
+				$dsecondweight = (floatval($d["secondnum"]) <= 0 ? 1 : floatval($d["secondnum"]));
29
+				$secondprice = 0;
30
+				if( $secondweight % $dsecondweight == 0 ) 
31
+				{
32
+					$secondprice = $secondweight / $dsecondweight * floatval($d["secondnumprice"]);
33
+				}
34
+				else 
35
+				{
36
+					$secondprice = ((int) ($secondweight / $dsecondweight) + 1) * floatval($d["secondnumprice"]);
37
+				}
38
+				$price += $secondprice;
39
+			}
40
+		}
41
+		else 
42
+		{
43
+			if( $param <= $d["firstweight"] ) 
44
+			{
45
+				if( 0 <= $param ) 
46
+				{
47
+					$price = floatval($d["firstprice"]);
48
+				}
49
+				else 
50
+				{
51
+					$price = 0;
52
+				}
53
+			}
54
+			else 
55
+			{
56
+				$price = floatval($d["firstprice"]);
57
+				$secondweight = $param - floatval($d["firstweight"]);
58
+				$dsecondweight = (floatval($d["secondweight"]) <= 0 ? 1 : floatval($d["secondweight"]));
59
+				$secondprice = 0;
60
+				if( $secondweight % $dsecondweight == 0 ) 
61
+				{
62
+					$secondprice = $secondweight / $dsecondweight * floatval($d["secondprice"]);
63
+				}
64
+				else 
65
+				{
66
+					$secondprice = ((int) ($secondweight / $dsecondweight) + 1) * floatval($d["secondprice"]);
67
+				}
68
+				$price += $secondprice;
69
+			}
70
+		}
71
+		return $price;
72
+	}
73
+	public function getCityDispatchPrice($areas, $address, $param, $d) 
74
+	{
75
+		$city = $address["city"];
76
+		$area_set = m("util")->get_area_config_set();
77
+		$new_area = intval($area_set["new_area"]);
78
+		if( empty($new_area) ) 
79
+		{
80
+			if( is_array($areas) && 0 < count($areas) ) 
81
+			{
82
+				foreach( $areas as $area ) 
83
+				{
84
+					$citys = explode(";", $area["citys"]);
85
+					$citys = array_filter($citys);
86
+					if( !empty($citys) && in_array($city, $citys) ) 
87
+					{
88
+						return $this->getDispatchPrice($param, $area, $d["calculatetype"]);
89
+					}
90
+				}
91
+			}
92
+		}
93
+		else 
94
+		{
95
+			$address_datavalue = trim($address["datavalue"]);
96
+			if( is_array($areas) && 0 < count($areas) ) 
97
+			{
98
+				foreach( $areas as $area ) 
99
+				{
100
+					$citys_code = explode(";", $area["citys_code"]);
101
+					if( in_array($address_datavalue, $citys_code) && !empty($citys_code) ) 
102
+					{
103
+						return $this->getDispatchPrice($param, $area, $d["calculatetype"]);
104
+					}
105
+				}
106
+			}
107
+		}
108
+		return $this->getDispatchPrice($param, $d);
109
+	}
110
+	public function getDefaultDispatch($merchid = 0) 
111
+	{
112
+		global $_W;
113
+		$sql = "select * from " . tablename("ewei_shop_dispatch") . " where isdefault=1 and uniacid=:uniacid and merchid=:merchid and enabled=1 Limit 1";
114
+		$params = array( ":uniacid" => $_W["uniacid"], ":merchid" => $merchid );
115
+		$data = pdo_fetch($sql, $params);
116
+		return $data;
117
+	}
118
+	public function getNewDispatch($merchid = 0) 
119
+	{
120
+		global $_W;
121
+		$sql = "select * from " . tablename("ewei_shop_dispatch") . " where uniacid=:uniacid and merchid=:merchid and enabled=1 order by id desc Limit 1";
122
+		$params = array( ":uniacid" => $_W["uniacid"], ":merchid" => $merchid );
123
+		$data = pdo_fetch($sql, $params);
124
+		return $data;
125
+	}
126
+	public function getOneDispatch($id) 
127
+	{
128
+		global $_W;
129
+		$params = array( ":uniacid" => $_W["uniacid"] );
130
+		if( $id == 0 ) 
131
+		{
132
+			$sql = "select * from " . tablename("ewei_shop_dispatch") . " where isdefault=1 and uniacid=:uniacid and enabled=1 Limit 1";
133
+		}
134
+		else 
135
+		{
136
+			$sql = "select * from " . tablename("ewei_shop_dispatch") . " where id=:id and uniacid=:uniacid and enabled=1 Limit 1";
137
+			$params[":id"] = $id;
138
+		}
139
+		$data = pdo_fetch($sql, $params);
140
+		return $data;
141
+	}
142
+	public function getAllNoDispatchAreas($areas = array( ), $type = 0) 
143
+	{
144
+		global $_W;
145
+		$tradeset = m("common")->getSysset("trade");
146
+		if( empty($type) ) 
147
+		{
148
+			$dispatchareas = iunserializer($tradeset["nodispatchareas"]);
149
+		}
150
+		else 
151
+		{
152
+			$dispatchareas = iunserializer($tradeset["nodispatchareas_code"]);
153
+		}
154
+		$set_citys = array( );
155
+		$dispatch_citys = array( );
156
+		if( !empty($dispatchareas) ) 
157
+		{
158
+			$set_citys = explode(";", trim($dispatchareas, ";"));
159
+		}
160
+		if( !empty($areas) ) 
161
+		{
162
+			$areas = iunserializer($areas);
163
+		}
164
+		if( !empty($areas) ) 
165
+		{
166
+			$dispatch_citys = explode(";", trim($areas, ";"));
167
+		}
168
+		$citys = array( );
169
+		if( !empty($set_citys) ) 
170
+		{
171
+			$citys = $set_citys;
172
+		}
173
+		if( !empty($dispatch_citys) ) 
174
+		{
175
+			$citys = array_merge($citys, $dispatch_citys);
176
+			$citys = array_unique($citys);
177
+		}
178
+		return $citys;
179
+	}
180
+	public function checkOnlyDispatchAreas($user_city_code, $dispatch_data) 
181
+	{
182
+		global $_W;
183
+		$area_set = m("util")->get_area_config_set();
184
+		$new_area = intval($area_set["new_area"]);
185
+		if( empty($new_area) ) 
186
+		{
187
+			$areas = $dispatch_data["nodispatchareas"];
188
+		}
189
+		else 
190
+		{
191
+			$areas = $dispatch_data["nodispatchareas_code"];
192
+		}
193
+		$isnoarea = 1;
194
+		if( !empty($user_city_code) && !empty($areas) ) 
195
+		{
196
+			$areas = iunserializer($areas);
197
+			$citys = explode(";", trim($areas, ";"));
198
+			if( in_array($user_city_code, $citys) ) 
199
+			{
200
+				$isnoarea = 0;
201
+			}
202
+		}
203
+		return $isnoarea;
204
+	}
205
+	public function getNoDispatchAreas($goods) 
206
+	{
207
+		global $_W;
208
+		if( $goods["type"] == 2 || $goods["type"] == 3 ) 
209
+		{
210
+			return "";
211
+		}
212
+		if( $goods["dispatchtype"] == 1 ) 
213
+		{
214
+			$dispatchareas = $this->getAllNoDispatchAreas();
215
+		}
216
+		else 
217
+		{
218
+			if( empty($goods["dispatchid"]) ) 
219
+			{
220
+				$dispatch = m("dispatch")->getDefaultDispatch($goods["merchid"]);
221
+			}
222
+			else 
223
+			{
224
+				$dispatch = m("dispatch")->getOneDispatch($goods["dispatchid"]);
225
+			}
226
+			if( empty($dispatch) ) 
227
+			{
228
+				$dispatch = m("dispatch")->getNewDispatch($goods["merchid"]);
229
+			}
230
+			if( empty($dispatch["isdispatcharea"]) ) 
231
+			{
232
+				$onlysent = 0;
233
+				$citys = $this->getAllNoDispatchAreas($dispatch["nodispatchareas"]);
234
+			}
235
+			else 
236
+			{
237
+				$onlysent = 1;
238
+				$dispatchareas = unserialize($dispatch["nodispatchareas"]);
239
+				$citys = explode(";", trim($dispatchareas, ";"));
240
+			}
241
+		}
242
+		return array( "onlysent" => $onlysent, "citys" => $citys, "enabled" => $dispatch["enabled"] );
243
+	}
244
+	public function getCityfreepricePrice($areas, $address) 
245
+	{
246
+		$city = $address["city"];
247
+		$area_set = m("util")->get_area_config_set();
248
+		$new_area = intval($area_set["new_area"]);
249
+		if( empty($new_area) ) 
250
+		{
251
+			if( is_array($areas) && 0 < count($areas) ) 
252
+			{
253
+				foreach( $areas as $area ) 
254
+				{
255
+					$citys = explode(";", $area["citys"]);
256
+					$citys = array_filter($citys);
257
+					if( !empty($citys) && in_array($city, $citys) ) 
258
+					{
259
+						return $area["freeprice"];
260
+					}
261
+				}
262
+			}
263
+		}
264
+		else 
265
+		{
266
+			$address_datavalue = trim($address["datavalue"]);
267
+			if( is_array($areas) && 0 < count($areas) ) 
268
+			{
269
+				foreach( $areas as $area ) 
270
+				{
271
+					$citys_code = explode(";", $area["citys_code"]);
272
+					if( in_array($address_datavalue, $citys_code) && !empty($citys_code) ) 
273
+					{
274
+						return $area["freeprice"];
275
+					}
276
+				}
277
+			}
278
+		}
279
+	}
280
+}
281
+?>

+ 162 - 0
addons/ewei_shopv2/core/model/excel.php Parādīt failu

@@ -0,0 +1,162 @@
1
+<?php
2
+if (!(defined('IN_IA'))) 
3
+{
4
+	exit('Access Denied');
5
+}
6
+class Excel_EweiShopV2Model 
7
+{
8
+	protected function column_str($key) 
9
+	{
10
+		$array = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ', 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BS', 'BT', 'BU', 'BV', 'BW', 'BX', 'BY', 'BZ', 'CA', 'CB', 'CC', 'CD', 'CE', 'CF', 'CG', 'CH', 'CI', 'CJ', 'CK', 'CL', 'CM', 'CN', 'CO', 'CP', 'CQ', 'CR', 'CS', 'CT', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DA', 'DB', 'DC', 'DD', 'DE', 'DF', 'DG', 'DH', 'DI', 'DJ', 'DK', 'DL', 'DM', 'DN', 'DO', 'DP', 'DQ', 'DR', 'DS', 'DT', 'DU', 'DV', 'DW', 'DX', 'DY', 'DZ', 'EA', 'EB', 'EC', 'ED', 'EE', 'EF', 'EG', 'EH', 'EI', 'EJ', 'EK', 'EL', 'EM', 'EN', 'EO', 'EP', 'EQ', 'ER', 'ES', 'ET', 'EU', 'EV', 'EW', 'EX', 'EY', 'EZ');
11
+		return $array[$key];
12
+	}
13
+	protected function column($key, $columnnum = 1) 
14
+	{
15
+		return $this->column_str($key) . $columnnum;
16
+	}
17
+	public function export($list, $params = array()) 
18
+	{
19
+		if (PHP_SAPI == 'cli') 
20
+		{
21
+			exit('This example should only be run from a Web Browser');
22
+		}
23
+		require_once IA_ROOT . '/framework/library/phpexcel/PHPExcel.php';
24
+		$data = m('common')->getSysset('shop');
25
+		$excel = new PHPExcel();
26
+		$excel->getProperties()->setCreator((empty($data['name']) ? '人人商城' : $data['name']))->setLastModifiedBy((empty($data['name']) ? '人人商城' : $data['name']))->setTitle('Office 2007 XLSX Test Document')->setSubject('Office 2007 XLSX Test Document')->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')->setKeywords('office 2007 openxml php')->setCategory('report file');
27
+		$sheet = $excel->setActiveSheetIndex(0);
28
+		$rownum = 1;
29
+		foreach ($params['columns'] as $key => $column ) 
30
+		{
31
+			$sheet->setCellValue($this->column($key, $rownum), $column['title']);
32
+			if (!(empty($column['width']))) 
33
+			{
34
+				$sheet->getColumnDimension($this->column_str($key))->setWidth($column['width']);
35
+			}
36
+		}
37
+		++$rownum;
38
+		$len = count($params['columns']);
39
+		foreach ($list as $row ) 
40
+		{
41
+			$i = 0;
42
+			while ($i < $len) 
43
+			{
44
+				$value = ((isset($row[$params['columns'][$i]['field']]) ? $row[$params['columns'][$i]['field']] : ''));
45
+				$sheet->setCellValue($this->column($i, $rownum), $value);
46
+				++$i;
47
+			}
48
+			++$rownum;
49
+		}
50
+		$excel->getActiveSheet()->setTitle($params['title']);
51
+		$filename = urlencode($params['title'] . '-' . date('Y-m-d H:i', time()));
52
+		ob_end_clean();
53
+		header('Content-Type: application/octet-stream');
54
+		header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"');
55
+		header('Cache-Control: max-age=0');
56
+		$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
57
+		$this->SaveViaTempFile($writer);
58
+		exit();
59
+	}
60
+	public function SaveViaTempFile($objWriter) 
61
+	{
62
+		$filePath = '' . rand(0, getrandmax()) . rand(0, getrandmax()) . '.tmp';
63
+		$objWriter->save($filePath);
64
+		readfile($filePath);
65
+		unlink($filePath);
66
+	}
67
+	public function temp($title, $columns = array()) 
68
+	{
69
+		if (PHP_SAPI == 'cli') 
70
+		{
71
+			exit('This example should only be run from a Web Browser');
72
+		}
73
+		require_once IA_ROOT . '/framework/library/phpexcel/PHPExcel.php';
74
+		$excel = new PHPExcel();
75
+		$excel->getProperties()->setCreator('人人商城')->setLastModifiedBy('人人商城')->setTitle('Office 2007 XLSX Test Document')->setSubject('Office 2007 XLSX Test Document')->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')->setKeywords('office 2007 openxml php')->setCategory('report file');
76
+		$sheet = $excel->setActiveSheetIndex(0);
77
+		$rownum = 1;
78
+		foreach ($columns as $key => $column ) 
79
+		{
80
+			$sheet->setCellValue($this->column($key, $rownum), $column['title']);
81
+			if (!(empty($column['width']))) 
82
+			{
83
+				$sheet->getColumnDimension($this->column_str($key))->setWidth($column['width']);
84
+			}
85
+		}
86
+		++$rownum;
87
+		$len = count($columns);
88
+		$k = 1;
89
+		while ($k <= 5000) 
90
+		{
91
+			$i = 0;
92
+			while ($i < $len) 
93
+			{
94
+				$sheet->setCellValue($this->column($i, $rownum), '');
95
+				++$i;
96
+			}
97
+			++$rownum;
98
+			++$k;
99
+		}
100
+		$excel->getActiveSheet()->setTitle($title);
101
+		$filename = urlencode($title);
102
+		header('Content-Type: application/octet-stream');
103
+		header('Content-Disposition: attachment;filename="' . $filename . '.xls"');
104
+		header('Cache-Control: max-age=0');
105
+		$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
106
+		$writer->save('php://output');
107
+		exit();
108
+	}
109
+	public function import($excefile) 
110
+	{
111
+		global $_W;
112
+		require_once IA_ROOT . '/framework/library/phpexcel/PHPExcel.php';
113
+		require_once IA_ROOT . '/framework/library/phpexcel/PHPExcel/IOFactory.php';
114
+		require_once IA_ROOT . '/framework/library/phpexcel/PHPExcel/Reader/Excel5.php';
115
+		$path = IA_ROOT . '/addons/ewei_shopv2/data/tmp/';
116
+		if (!(is_dir($path))) 
117
+		{
118
+			load()->func('file');
119
+			mkdirs($path, '0777');
120
+		}
121
+		$filename = $_FILES[$excefile]['name'];
122
+		$tmpname = $_FILES[$excefile]['tmp_name'];
123
+		if (empty($tmpname)) 
124
+		{
125
+			message('请选择要上传的Excel文件!', '', 'error');
126
+		}
127
+		$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
128
+		if (($ext != 'xlsx') && ($ext != 'xls')) 
129
+		{
130
+			message('请上传 xls 或 xlsx 格式的Excel文件!', '', 'error');
131
+		}
132
+		$file = time() . $_W['uniacid'] . '.' . $ext;
133
+		$uploadfile = $path . $file;
134
+		$result = move_uploaded_file($tmpname, $uploadfile);
135
+		if (!($result)) 
136
+		{
137
+			message('上传Excel 文件失败, 请重新上传!', '', 'error');
138
+		}
139
+		$reader = PHPExcel_IOFactory::createReader(($ext == 'xls' ? 'Excel5' : 'Excel2007'));
140
+		$excel = $reader->load($uploadfile);
141
+		$sheet = $excel->getActiveSheet();
142
+		$highestRow = $sheet->getHighestRow();
143
+		$highestColumn = $sheet->getHighestColumn();
144
+		$highestColumnCount = PHPExcel_Cell::columnIndexFromString($highestColumn);
145
+		$values = array();
146
+		$row = 1;
147
+		while ($row <= $highestRow) 
148
+		{
149
+			$rowValue = array();
150
+			$col = 0;
151
+			while ($col < $highestColumnCount) 
152
+			{
153
+				$rowValue[] = (string) $sheet->getCellByColumnAndRow($col, $row)->getValue();
154
+				++$col;
155
+			}
156
+			$values[] = $rowValue;
157
+			++$row;
158
+		}
159
+		return $values;
160
+	}
161
+}
162
+?>

+ 20 - 0
addons/ewei_shopv2/core/model/express.php Parādīt failu

@@ -0,0 +1,20 @@
1
+<?php
2
+class Express_EweiShopV2Model
3
+{
4
+	/**
5
+     * 获取快递列表
6
+     */
7
+	public function getExpressList()
8
+	{
9
+		global $_W;
10
+		$sql = 'select * from ' . tablename('ewei_shop_express') . ' where status=1 order by displayorder desc,id asc';
11
+		$data = pdo_fetchall($sql);
12
+		return $data;
13
+	}
14
+}
15
+
16
+if (!defined('IN_IA')) {
17
+	exit('Access Denied');
18
+}
19
+
20
+?>

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1731 - 0
addons/ewei_shopv2/core/model/finance.php


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1203 - 0
addons/ewei_shopv2/core/model/goods.php


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1082 - 0
addons/ewei_shopv2/core/model/member.php


+ 84 - 0
addons/ewei_shopv2/core/model/message.php Parādīt failu

@@ -0,0 +1,84 @@
1
+<?php  if( !defined("IN_IA") ) 
2
+{
3
+	exit( "Access Denied" );
4
+}
5
+class Message_EweiShopV2Model 
6
+{
7
+	public function sendTplNotice($touser, $template_id, $postdata, $url = "", $account = NULL, $miniprogram = array( )) 
8
+	{
9
+		if( !$account ) 
10
+		{
11
+			$account = m("common")->getAccount();
12
+		}
13
+		if( !$account ) 
14
+		{
15
+			return NULL;
16
+		}
17
+		return $account->sendTplNotice($touser, $template_id, $postdata, $url, "#FF683F", $miniprogram);
18
+	}
19
+	public function sendCustomNotice($openid, $msg, $url = "", $account = NULL) 
20
+	{
21
+		if( !$account ) 
22
+		{
23
+			$account = m("common")->getAccount();
24
+		}
25
+		if( !$account ) 
26
+		{
27
+			return NULL;
28
+		}
29
+		$content = "";
30
+		if( is_array($msg) ) 
31
+		{
32
+			foreach( $msg as $key => $value ) 
33
+			{
34
+				if( !empty($value["title"]) ) 
35
+				{
36
+					$content .= $value["title"] . ":" . $value["value"] . "\n";
37
+				}
38
+				else 
39
+				{
40
+					$content .= $value["value"] . "\n";
41
+					if( $key == 0 ) 
42
+					{
43
+						$content .= "\n";
44
+					}
45
+				}
46
+			}
47
+		}
48
+		else 
49
+		{
50
+			$content = addslashes($msg);
51
+		}
52
+		if( !empty($url) ) 
53
+		{
54
+			$content .= "<a href='" . $url . "'>点击查看详情</a>";
55
+		}
56
+		return $account->sendCustomNotice(array( "touser" => $openid, "msgtype" => "text", "text" => array( "content" => urlencode($content) ) ));
57
+	}
58
+	public function sendImage($openid, $mediaid) 
59
+	{
60
+		$account = m("common")->getAccount();
61
+		return $account->sendCustomNotice(array( "touser" => $openid, "msgtype" => "image", "image" => array( "media_id" => $mediaid ) ));
62
+	}
63
+	public function sendNews($openid, $articles, $account = NULL) 
64
+	{
65
+		if( !$account ) 
66
+		{
67
+			$account = m("common")->getAccount();
68
+		}
69
+		return $account->sendCustomNotice(array( "touser" => $openid, "msgtype" => "news", "news" => array( "articles" => $articles ) ));
70
+	}
71
+	public function sendTexts($openid, $content, $url = "", $account = NULL) 
72
+	{
73
+		if( !$account ) 
74
+		{
75
+			$account = m("common")->getAccount();
76
+		}
77
+		if( !empty($url) ) 
78
+		{
79
+			$content .= "\n<a href='" . $url . "'>点击查看详情</a>";
80
+		}
81
+		return $account->sendCustomNotice(array( "touser" => $openid, "msgtype" => "text", "text" => array( "content" => urlencode($content) ) ));
82
+	}
83
+}
84
+?>

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 2174 - 0
addons/ewei_shopv2/core/model/notice.php


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 2544 - 0
addons/ewei_shopv2/core/model/order.php


+ 89 - 0
addons/ewei_shopv2/core/model/ordergoods.php Parādīt failu

@@ -0,0 +1,89 @@
1
+<?php
2
+if (!defined('IN_IA')) {
3
+    exit('Access Denied');
4
+}
5
+
6
+class Ordergoods_EweiShopV2Model
7
+{
8
+
9
+    /**
10
+     * 计算订单中商品累计赠送的积分
11
+     * @param type $order
12
+     */
13
+    function getGoodsCredit1($goods)
14
+    {
15
+
16
+        $credit1 = 0;
17
+        //积分累计
18
+        $gcredit = trim($goods['credit']);
19
+        if (!empty($gcredit)) {
20
+            if (strexists($gcredit, '%')) {
21
+                //按比例计算
22
+                $credit1 += intval(floatval(str_replace('%', '', $gcredit)) / 100 * $goods['realprice']);
23
+            } else {
24
+                //按固定值计算
25
+                $credit1 += intval($goods['credit']) * $goods['total'];
26
+            }
27
+        }
28
+
29
+        return $credit1;
30
+    }
31
+
32
+    /**
33
+     * 计算订单中商品累计赠送的余额
34
+     * @param type $order
35
+     */
36
+    function getGoodsCredit2($goods)
37
+    {
38
+
39
+        $credit2 = 0;
40
+        $gbalance = trim($goods['money']);
41
+        if (!empty($gbalance)) {
42
+            if (strexists($gbalance, '%')) {
43
+                //按比例计算
44
+                $credit2 += round(floatval(str_replace('%', '', $gbalance)) / 100 * $goods['realprice'], 2);
45
+            } else {
46
+                //按固定值计算
47
+                $credit2 += round($goods['money'], 2) * $goods['total'];
48
+            }
49
+        }
50
+
51
+        return $credit2;
52
+    }
53
+
54
+    /**
55
+     * //处理订单库存情况(单品退换货)
56
+     * @param type $goods
57
+     */
58
+    function setStock($goods)
59
+    {
60
+        global $_W;
61
+
62
+        if (!empty($goods['optionid'])) {
63
+            //规格
64
+            $option = m('goods')->getOption($goods['goodsid'], $goods['optionid']);
65
+
66
+            if (!empty($option) && $option['stock'] != -1) {
67
+                //增加库存
68
+                $stock = $option['stock'] + $goods['total'];
69
+
70
+                if (!empty($stock)){
71
+                    pdo_update('ewei_shop_goods_option', array('stock' => $stock), array('uniacid' => $_W['uniacid'], 'goodsid' => $goods['goodsid'], 'id' => $goods['optionid']));
72
+                }
73
+            }
74
+        }
75
+
76
+
77
+        $totalstock = $goods['goodstotal'] + $goods['total'];
78
+        if (!empty($totalstock)){
79
+            pdo_update('ewei_shop_goods', array('total' => $totalstock), array('uniacid' => $_W['uniacid'], 'id' => $goods['goodsid']));
80
+        }
81
+
82
+
83
+    }
84
+
85
+
86
+
87
+
88
+
89
+}

+ 0 - 0
addons/ewei_shopv2/core/model/pay.php Parādīt failu


Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels