coupon.class.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->classs('weixin.account');
  8. class coupon extends WeixinAccount {
  9. public $account = null;
  10. public function __construct($acid = '') {
  11. $this->account_api = self::create($acid);
  12. $this->account = $this->account_api->account;
  13. }
  14. public function getAccessToken() {
  15. return $this->account_api->getAccessToken();
  16. }
  17. public function getCardTicket() {
  18. $cachekey = cache_system_key('cardticket', array('uniacid' => $this->account['uniacid']));
  19. $cache = cache_load($cachekey);
  20. if (!empty($cache) && !empty($cache['ticket']) && $cache['expire'] > TIMESTAMP) {
  21. $this->account['card_ticket'] = $cache;
  22. return $cache['ticket'];
  23. }
  24. load()->func('communication');
  25. $access_token = $this->getAccessToken();
  26. if (is_error($access_token)) {
  27. return $access_token;
  28. }
  29. $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={$access_token}&type=wx_card";
  30. $content = ihttp_get($url);
  31. if (is_error($content)) {
  32. return error(-1, '调用接口获取微信公众号 card_ticket 失败, 错误信息: ' . $content['message']);
  33. }
  34. $result = @json_decode($content['content'], true);
  35. if (empty($result) || 0 != intval(($result['errcode'])) || 'ok' != $result['errmsg']) {
  36. return error(-1, '获取微信公众号 card_ticket 结果错误, 错误信息: ' . $result['errmsg']);
  37. }
  38. $record = array();
  39. $record['ticket'] = $result['ticket'];
  40. $record['expire'] = TIMESTAMP + $result['expires_in'] - 200;
  41. $this->account['card_ticket'] = $record;
  42. cache_write($cachekey, $record);
  43. return $record['ticket'];
  44. }
  45. public function LocationLogoupload($logo) {
  46. global $_W;
  47. if (!strexists($logo, 'http://') && !strexists($logo, 'https://')) {
  48. $path = rtrim(IA_ROOT . '/' . $_W['config']['upload']['attachdir'], '/') . '/';
  49. if (empty($logo) || !file_exists($path . $logo)) {
  50. return error(-1, '商户LOGO不存在');
  51. }
  52. } else {
  53. return error(-1, '商户LOGO只能上传本地图片');
  54. }
  55. $token = $this->getAccessToken();
  56. if (is_error($token)) {
  57. return $token;
  58. }
  59. $url = "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token={$token}";
  60. $data = array(
  61. 'buffer' => '@' . $path . $logo,
  62. );
  63. load()->func('communication');
  64. $response = ihttp_request($url, $data);
  65. if (is_error($response)) {
  66. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  67. }
  68. $result = @json_decode($response['content'], true);
  69. if (empty($result)) {
  70. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  71. } elseif (!empty($result['errcode'])) {
  72. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},信息详情:{$this->errorCode($result['errcode'])}");
  73. }
  74. return $result;
  75. }
  76. public function SetTestWhiteList($data) {
  77. global $_W;
  78. $token = $this->getAccessToken();
  79. if (is_error($token)) {
  80. return $token;
  81. }
  82. $url = "https://api.weixin.qq.com/card/testwhitelist/set?access_token={$token}";
  83. load()->func('communication');
  84. $response = ihttp_request($url, json_encode($data));
  85. if (is_error($response)) {
  86. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  87. }
  88. $result = @json_decode($response['content'], true);
  89. if (empty($result)) {
  90. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  91. } elseif (!empty($result['errcode'])) {
  92. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},信息详情:{$this->errorCode($result['errcode'])}");
  93. }
  94. return $result;
  95. }
  96. public function LocationAdd($data) {
  97. if (empty($data)) {
  98. return error(-1, '门店信息错误');
  99. }
  100. $token = $this->getAccessToken();
  101. if (is_error($token)) {
  102. return $token;
  103. }
  104. if (!empty($data['category'])) {
  105. $data['category'] = array(rtrim(implode(',', array_values($data['category'])), ','));
  106. }
  107. $data['categories'] = $data['category'];
  108. unset($data['category']);
  109. $data['offset_type'] = 1;
  110. $post = array(
  111. 'business' => array(
  112. 'base_info' => $data,
  113. ),
  114. );
  115. $post = stripslashes(urldecode(ijson_encode($post, JSON_UNESCAPED_UNICODE)));
  116. $url = "http://api.weixin.qq.com/cgi-bin/poi/addpoi?access_token={$token}";
  117. $result = $this->requestApi($url, $post);
  118. return $result;
  119. }
  120. public function LocationEdit($data) {
  121. if (empty($data)) {
  122. return error(-1, '门店信息错误');
  123. }
  124. $post = array(
  125. 'business' => array(
  126. 'base_info' => $data,
  127. ),
  128. );
  129. $token = $this->getAccessToken();
  130. if (is_error($token)) {
  131. return $token;
  132. }
  133. $url = "http://api.weixin.qq.com/cgi-bin/poi/updatepoi?access_token={$token}";
  134. load()->func('communication');
  135. $response = ihttp_request($url, urldecode(json_encode($post)));
  136. if (is_error($response)) {
  137. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  138. }
  139. $result = @json_decode($response['content'], true);
  140. if (empty($result)) {
  141. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  142. } elseif (!empty($result['errcode'])) {
  143. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},错误详情:{$this->errorCode($result['errcode'])}");
  144. }
  145. return $result;
  146. }
  147. public function LocationDel($id) {
  148. if (empty($id)) {
  149. return error(-1, '门店信息错误');
  150. }
  151. $post = array(
  152. 'poi_id' => $id,
  153. );
  154. $token = $this->getAccessToken();
  155. if (is_error($token)) {
  156. return $token;
  157. }
  158. $url = "http://api.weixin.qq.com/cgi-bin/poi/delpoi?access_token={$token}";
  159. load()->func('communication');
  160. $response = ihttp_request($url, json_encode($post));
  161. if (is_error($response)) {
  162. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  163. }
  164. $result = @json_decode($response['content'], true);
  165. if (empty($result)) {
  166. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  167. } elseif (!empty($result['errcode'])) {
  168. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},错误详情:{$this->errorCode($result['errcode'])}");
  169. }
  170. return $result;
  171. }
  172. public function LocationBatchGet($data = array()) {
  173. if (empty($data['begin'])) {
  174. $data['begin'] = 0;
  175. }
  176. if (empty($data['limit'])) {
  177. $data['limit'] = 50;
  178. }
  179. $token = $this->getAccessToken();
  180. if (is_error($token)) {
  181. return $token;
  182. }
  183. $url = "http://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token={$token}";
  184. load()->func('communication');
  185. $response = ihttp_request($url, json_encode($data));
  186. if (is_error($response)) {
  187. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  188. }
  189. $result = @json_decode($response['content'], true);
  190. if (empty($result)) {
  191. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  192. } elseif (!empty($result['errcode'])) {
  193. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},错误详情:{$this->errorCode($result['errcode'])}");
  194. }
  195. return $result;
  196. }
  197. public function LocationGet($id) {
  198. $token = $this->getAccessToken();
  199. if (is_error($token)) {
  200. return $token;
  201. }
  202. $data = array(
  203. 'poi_id' => $id,
  204. );
  205. $url = "http://api.weixin.qq.com/cgi-bin/poi/getpoi?access_token={$token}";
  206. load()->func('communication');
  207. $response = ihttp_request($url, json_encode($data));
  208. if (is_error($response)) {
  209. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  210. }
  211. $result = @json_decode($response['content'], true);
  212. if (empty($result)) {
  213. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  214. } elseif (!empty($result['errcode'])) {
  215. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},错误详情:{$this->errorCode($result['errcode'])}");
  216. }
  217. return $result;
  218. }
  219. public function GetColors() {
  220. $token = $this->getAccessToken();
  221. if (is_error($token)) {
  222. return $token;
  223. }
  224. $url = "https://api.weixin.qq.com/card/getcolors?access_token={$token}";
  225. load()->func('communication');
  226. $response = ihttp_request($url);
  227. if (is_error($response)) {
  228. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  229. }
  230. $result = @json_decode($response['content'], true);
  231. if (empty($result)) {
  232. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  233. } elseif (!empty($result['errcode'])) {
  234. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},错误详情:{$this->errorCode($result['errcode'])}");
  235. }
  236. return $result;
  237. }
  238. public function isCouponSupported() {
  239. global $_W;
  240. load()->model('module');
  241. $we7_coupon_module = module_fetch('we7_coupon');
  242. $setting = array();
  243. if (!empty($we7_coupon_module)) {
  244. $setting = $we7_coupon_module['config'];
  245. } else {
  246. $setting = uni_setting($_W['uniacid'], array('coupon_type'));
  247. }
  248. if ($_W['account']['level'] != ACCOUNT_SERVICE_VERIFY && $_W['account']['level'] != ACCOUNT_SUBSCRIPTION_VERIFY) {
  249. return false;
  250. } else {
  251. if (!empty($setting['setting']['coupon_type'])) {
  252. if ($setting['setting']['coupon_type'] == SYSTEM_COUPON) {
  253. return false;
  254. } else {
  255. return true;
  256. }
  257. } else {
  258. if (SYSTEM_COUPON == $setting['coupon_type']) {
  259. return false;
  260. } else {
  261. return true;
  262. }
  263. }
  264. }
  265. }
  266. public function CreateCard($card) {
  267. $token = $this->getAccessToken();
  268. if (is_error($token)) {
  269. return $token;
  270. }
  271. $url = "https://api.weixin.qq.com/card/create?access_token={$token}";
  272. load()->func('communication');
  273. $card = stripslashes(urldecode(ijson_encode($card, JSON_UNESCAPED_UNICODE)));
  274. $response = $this->requestApi($url, $card);
  275. return $response;
  276. }
  277. public function DeleteCard($card_id) {
  278. $token = $this->getAccessToken();
  279. if (is_error($token)) {
  280. return $token;
  281. }
  282. $url = "https://api.weixin.qq.com/card/delete?access_token={$token}";
  283. load()->func('communication');
  284. $card = json_encode(array('card_id' => $card_id));
  285. $response = ihttp_request($url, $card);
  286. if (is_error($response)) {
  287. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  288. }
  289. $result = @json_decode($response['content'], true);
  290. if (empty($result)) {
  291. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  292. } elseif (!empty($result['errcode'])) {
  293. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},错误详情:{$this->errorCode($result['errcode'])}");
  294. }
  295. return $result;
  296. }
  297. public function setActivateUserForm($card_id) {
  298. global $_W;
  299. $token = $this->getAccessToken();
  300. if (is_error($token)) {
  301. return $token;
  302. }
  303. $data['required_form']['common_field_id_list'] = array('USER_FORM_INFO_FLAG_MOBILE');
  304. $data['card_id'] = $card_id;
  305. $data['bind_old_card'] = array('name' => '绑定老会员卡', 'url' => 'www.weixin.qq.com');
  306. $url = "https://api.weixin.qq.com/card/membercard/activateuserform/set?access_token={$token}";
  307. load()->func('communication');
  308. $result = $this->requestApi($url, json_encode($data));
  309. return $result;
  310. }
  311. public function activateMemberCard($data) {
  312. global $_W;
  313. $token = $this->getAccessToken();
  314. if (is_error($token)) {
  315. return $token;
  316. }
  317. $url = "https://api.weixin.qq.com/card/membercard/activate?access_token={$token}";
  318. load()->func('communication');
  319. $result = $this->requestApi($url, json_encode($data));
  320. return $result;
  321. }
  322. public function ModifyStockCard($card_id, $num) {
  323. $data['card_id'] = trim($card_id);
  324. $data['increase_stock_value'] = 0;
  325. $data['reduce_stock_value'] = 0;
  326. $num = intval($num);
  327. ($num > 0) && ($data['increase_stock_value'] = $num);
  328. ($num < 0) && ($data['reduce_stock_value'] = abs($num));
  329. $token = $this->getAccessToken();
  330. if (is_error($token)) {
  331. return $token;
  332. }
  333. $url = "https://api.weixin.qq.com/card/modifystock?access_token={$token}";
  334. load()->func('communication');
  335. $response = ihttp_request($url, json_encode($data));
  336. if (is_error($response)) {
  337. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  338. }
  339. $result = @json_decode($response['content'], true);
  340. if (empty($result)) {
  341. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  342. } elseif (!empty($result['errcode'])) {
  343. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},错误详情:{$this->errorCode($result['errcode'])}");
  344. }
  345. return $result;
  346. }
  347. public function QrCard($card_id, $sceneid, $expire = '') {
  348. $token = $this->getAccessToken();
  349. if (is_error($token)) {
  350. return $token;
  351. }
  352. $url = "https://api.weixin.qq.com/card/qrcode/create?access_token={$token}";
  353. load()->func('communication');
  354. $data = array(
  355. 'action_name' => 'QR_CARD',
  356. 'expire_seconds' => "{$expire}",
  357. 'action_info' => array(
  358. 'card' => array(
  359. 'card_id' => strval($card_id),
  360. 'code' => '',
  361. 'openid' => '',
  362. 'is_unique_code' => false,
  363. 'outer_id' => $sceneid,
  364. ),
  365. ),
  366. );
  367. $result = $this->requestApi($url, json_encode($data));
  368. return $result;
  369. }
  370. public function sendCoupons($coupon, $openids) {
  371. $token = $this->getAccessToken();
  372. if (is_error($token)) {
  373. return $token;
  374. }
  375. $post = array(
  376. 'touser' => $openids,
  377. 'wxcard' => array('card_id' => $coupon),
  378. 'msgtype' => 'wxcard',
  379. );
  380. $url = 'https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=' . $token;
  381. $result = $this->requestApi($url, json_encode($post));
  382. return $result;
  383. }
  384. public function UnavailableCode($data) {
  385. $token = $this->getAccessToken();
  386. if (is_error($token)) {
  387. return $token;
  388. }
  389. $url = "https://api.weixin.qq.com/card/code/unavailable?access_token={$token}";
  390. load()->func('communication');
  391. $response = ihttp_request($url, json_encode($data));
  392. if (is_error($response)) {
  393. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  394. }
  395. $result = @json_decode($response['content'], true);
  396. if (empty($result)) {
  397. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  398. } elseif (!empty($result['errcode'])) {
  399. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},错误详情:{$this->errorCode($result['errcode'])}");
  400. }
  401. return $result;
  402. }
  403. public function ConsumeCode($data) {
  404. $token = $this->getAccessToken();
  405. if (is_error($token)) {
  406. return $token;
  407. }
  408. $url = "https://api.weixin.qq.com/card/code/consume?access_token={$token}";
  409. load()->func('communication');
  410. $response = ihttp_request($url, json_encode($data));
  411. if (is_error($response)) {
  412. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  413. }
  414. $result = @json_decode($response['content'], true);
  415. if (empty($result)) {
  416. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  417. } elseif (!empty($result['errcode'])) {
  418. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},错误详情:{$this->errorCode($result['errcode'])}");
  419. }
  420. return $result;
  421. }
  422. public function selfConsume($data) {
  423. $token = $this->getAccessToken();
  424. if (is_error($token)) {
  425. return $token;
  426. }
  427. $url = "https://api.weixin.qq.com/card/selfconsumecell/set?access_token={$token}";
  428. load()->func('communication');
  429. $response = ihttp_request($url, json_encode($data));
  430. if (is_error($response)) {
  431. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  432. }
  433. $result = @json_decode($response['content'], true);
  434. if (empty($result)) {
  435. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  436. } elseif (!empty($result['errcode'])) {
  437. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},错误详情:{$this->errorCode($result['errcode'])}");
  438. }
  439. return $result;
  440. }
  441. public function DecryptCode($data) {
  442. $token = $this->getAccessToken();
  443. if (is_error($token)) {
  444. return $token;
  445. }
  446. $url = "https://api.weixin.qq.com/card/code/decrypt?access_token={$token}";
  447. load()->func('communication');
  448. $response = ihttp_request($url, json_encode($data));
  449. if (is_error($response)) {
  450. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  451. }
  452. $result = @json_decode($response['content'], true);
  453. if (empty($result)) {
  454. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  455. } elseif (!empty($result['errcode'])) {
  456. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},错误详情:{$this->errorCode($result['errcode'])}");
  457. }
  458. return $result;
  459. }
  460. public function fetchCard($card_id) {
  461. $token = $this->getAccessToken();
  462. if (is_error($token)) {
  463. return $token;
  464. }
  465. $data = array(
  466. 'card_id' => $card_id,
  467. );
  468. $url = "https://api.weixin.qq.com/card/get?access_token={$token}";
  469. load()->func('communication');
  470. $response = ihttp_request($url, json_encode($data));
  471. if (is_error($response)) {
  472. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  473. }
  474. $result = @json_decode($response['content'], true);
  475. if (empty($result)) {
  476. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  477. } elseif (!empty($result['errcode'])) {
  478. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},错误详情:{$this->errorCode($result['errcode'])}");
  479. }
  480. return $result['card'];
  481. }
  482. public function updateMemberCard($post) {
  483. $token = $this->getAccessToken();
  484. if (is_error($token)) {
  485. return $token;
  486. }
  487. $url = "https://api.weixin.qq.com/card/update?access_token={$token}";
  488. $result = $this->requestApi($url, urldecode(json_encode($post)));
  489. return $result;
  490. }
  491. public function batchgetCard($data) {
  492. $token = $this->getAccessToken();
  493. if (is_error($token)) {
  494. return $token;
  495. }
  496. $url = "https://api.weixin.qq.com/card/batchget?access_token={$token}";
  497. load()->func('communication');
  498. $response = ihttp_request($url, json_encode($data));
  499. if (is_error($response)) {
  500. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  501. }
  502. $result = @json_decode($response['content'], true);
  503. if (empty($result)) {
  504. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  505. } elseif (!empty($result['errcode'])) {
  506. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},错误详情:{$this->errorCode($result['errcode'])}");
  507. }
  508. return $result;
  509. }
  510. public function updateCard($card_id) {
  511. $token = $this->getAccessToken();
  512. if (is_error($token)) {
  513. return $token;
  514. }
  515. $data = array(
  516. 'card_id' => $card_id,
  517. );
  518. $url = "https://api.weixin.qq.com/card/membercard/activate?access_token={$token}";
  519. load()->func('communication');
  520. $response = ihttp_request($url, json_encode($data));
  521. if (is_error($response)) {
  522. return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  523. }
  524. $result = @json_decode($response['content'], true);
  525. if (empty($result)) {
  526. return error(-1, "接口调用失败, 元数据: {$response['meta']}");
  527. } elseif (!empty($result['errcode'])) {
  528. return error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']},错误详情:{$this->errorCode($result['errcode'])}");
  529. }
  530. return $result;
  531. }
  532. public function PayConsumeCode($data) {
  533. $code_error['uniacid'] = $this->account['uniacid'];
  534. $code_error['acid'] = $this->account['acid'];
  535. $code_error['type'] = 2;
  536. $code_error['message'] = $data['encrypt_code'];
  537. $code_error['dateline'] = time();
  538. $code_error['module'] = $data['module'];
  539. $code_error['params'] = $data['card_id'];
  540. $code = $this->DecryptCode(array('encrypt_code' => $data['encrypt_code']));
  541. if (is_error($code)) {
  542. pdo_insert('core_queue', $code_error);
  543. } else {
  544. $sumecode = $this->ConsumeCode(array('code' => $code['code']));
  545. if (is_error($sumecode)) {
  546. pdo_insert('core_queue', $code_error);
  547. } else {
  548. pdo_update('coupon_record', array('status' => 3, 'usetime' => time()), array('acid' => $this->account['acid'], 'code' => $code['code'], 'card_id' => $data['card_id']));
  549. }
  550. }
  551. return true;
  552. }
  553. public function SignatureCard($data) {
  554. $ticket = $this->getCardTicket();
  555. if (is_error($ticket)) {
  556. return $ticket;
  557. }
  558. $data[] = $ticket;
  559. sort($data, SORT_STRING);
  560. return sha1(implode($data));
  561. }
  562. public function BuildCardExt($id, $openid = '', $type = 'coupon') {
  563. global $_W;
  564. if ('membercard' == $type) {
  565. $card_id = pdo_getcolumn('mc_card', array('uniacid' => $_W['uniacid']), 'card_id');
  566. } else {
  567. $acid = $this->account['acid'];
  568. $card_id = pdo_fetchcolumn('SELECT card_id FROM ' . tablename('coupon') . ' WHERE acid = :acid AND id = :id', array(':acid' => $acid, ':id' => $id));
  569. if (empty($card_id)) {
  570. return error(-1, '卡券id不合法');
  571. }
  572. }
  573. if (empty($card_id)) {
  574. $card_id = $id;
  575. }
  576. $time = TIMESTAMP;
  577. $sign = array($card_id, $time);
  578. $signature = $this->SignatureCard($sign);
  579. if (is_error($signature)) {
  580. return $signature;
  581. }
  582. $cardExt = array('timestamp' => $time, 'signature' => $signature);
  583. $cardExt = json_encode($cardExt);
  584. return array('card_id' => $card_id, 'card_ext' => $cardExt);
  585. }
  586. public function AddCard($id) {
  587. $card = $this->BuildCardExt($id);
  588. if (is_error($card)) {
  589. return $card;
  590. }
  591. $url = murl('activity/coupon/mine');
  592. return <<<EOF
  593. wx.ready(function(){
  594. wx.addCard({
  595. cardList:[
  596. {
  597. cardId:'{$card['card_id']}',
  598. cardExt:'{$card['card_ext']}'
  599. }
  600. ],
  601. success: function (res) {
  602. location.href="{$url}";
  603. }
  604. });
  605. });
  606. EOF;
  607. }
  608. public function OpenCard($id, $code) {
  609. $card = $this->BuildCardExt($id);
  610. if (is_error($card)) {
  611. return $card;
  612. }
  613. $url = murl('activity/coupon/mine');
  614. return <<<EOF
  615. wx.ready(function(){
  616. wx.openCard({
  617. cardList:[
  618. {
  619. cardId : "{$card['card_id']}",
  620. code : "{$code}"
  621. }
  622. ],
  623. });
  624. });
  625. EOF;
  626. }
  627. public function ChooseCard($card_id) {
  628. if (empty($card_id)) {
  629. return error(-1, '卡券不存在');
  630. }
  631. $time = TIMESTAMP;
  632. $randstr = random(8);
  633. $sign = array($card_id, $time, $randstr, $this->account['key']);
  634. $signature = $this->SignatureCard($sign);
  635. if (is_error($signature)) {
  636. return $signature;
  637. }
  638. $url = murl('wechat/pay/card');
  639. return <<<EOF
  640. wx.ready(function(){
  641. wx.chooseCard({
  642. shopId: '',
  643. cardType: '',
  644. cardId:'{$card_id}',
  645. timestamp:{$time},
  646. nonceStr:'{$randstr}',
  647. signType:'SHA1',
  648. cardSign:'{$signature}',
  649. success: function(res) {
  650. if(res.errMsg == 'chooseCard:ok') {
  651. eval("var rs = " + res.cardList);
  652. $.post('{$url}', {'card_id':rs[0].card_id}, function(data){
  653. var data = $.parseJSON(data);
  654. if(!data.errno) {
  655. var card = data.error;
  656. if(card.type == 'discount') {
  657. }
  658. } else {
  659. u.message('卡券不存在', '', 'error');
  660. }
  661. });
  662. } else {
  663. u.message('使用卡券失败', '', 'error');
  664. }
  665. }
  666. });
  667. });
  668. EOF;
  669. }
  670. public function BatchAddCard($data) {
  671. $acid = $this->account['acid'];
  672. $condition = '';
  673. $params = array();
  674. if (!empty($data['type'])) {
  675. $condition .= ' AND type = :type';
  676. $params[':type'] = $data['type'];
  677. } else {
  678. $ids = array();
  679. foreach ($data as $da) {
  680. $da = intval($da);
  681. if ($da > 0) {
  682. $ids[] = $da;
  683. }
  684. }
  685. if (empty($ids)) {
  686. $condition = '';
  687. } else {
  688. $ids_str = implode(', ', $ids);
  689. $condition .= ' AND id IN (' . $ids_str . ')';
  690. }
  691. }
  692. $card = array();
  693. if (!empty($condition)) {
  694. $params[':acid'] = $acid;
  695. $card = pdo_fetchall('SELECT id, card_id FROM ' . tablename('coupon') . ' WHERE acid = :acid ' . $condition, $params);
  696. }
  697. foreach ($card as $ca) {
  698. $time = TIMESTAMP;
  699. $sign = array($ca['card_id'], $time);
  700. $signature = $this->SignatureCard($sign);
  701. if (is_error($signature)) {
  702. return $signature;
  703. }
  704. $post[] = array(
  705. 'cardId' => trim($ca['card_id']),
  706. 'cardExt' => array('timestamp' => $time, 'signature' => $signature),
  707. );
  708. }
  709. if (!empty($post)) {
  710. $card_json = json_encode($post);
  711. echo <<<EOF
  712. <script>
  713. wx.ready(function(){
  714. wx.addCard({
  715. cardList : {$card_json}, // 需要添加的卡券列表
  716. success: function (res) {
  717. alert(JSON.stringify(res));
  718. var cardList = res.cardList; // 添加的卡券列表信息
  719. }
  720. });
  721. });
  722. </script>
  723. EOF;
  724. } else {
  725. echo <<<EOF
  726. <script>
  727. </script>
  728. EOF;
  729. }
  730. }
  731. }
  732. define('COUPON_CODE_TYPE_TEXT', 1);
  733. define('COUPON_CODE_TYPE_QRCODE', 2);
  734. define('COUPON_CODE_TYPE_BARCODE', 3);
  735. define('COUPON_TIME_TYPE_RANGE', 1);
  736. define('COUPON_TIME_TYPE_FIX', 2);
  737. class Card {
  738. public $card_id = '';
  739. public $logo_url = '';
  740. public $brand_name = '';
  741. public $code_type = CODE_TYPE_BARCODE;
  742. public $title = '';
  743. public $sub_title = '';
  744. public $color = 'Color082';
  745. public $notice = '';
  746. public $service_phone = '';
  747. public $description = '';
  748. public $sku = array('quantity' => 50000);
  749. public $date_info = array('type' => COUPON_TIME_TYPE_RANGE);
  750. public $location_id_list = array();
  751. public $get_limit = 10; public $can_share = true;
  752. public $can_give_friend = true; public $use_custom_code = false; public $bind_openid = false; public $source = ''; public $status = ''; public $promotion_url_name = ''; public $promotion_url_sub_title = '';
  753. public $promotion_url = '';
  754. public $custom_url_name = ''; public $custom_url_sub_title = '';
  755. public $custom_url = '';
  756. public $center_title = ''; public $center_sub_title = '';
  757. public $center_url = '';
  758. public $need_push_on_view = false; public $pay_info = array();
  759. public $get_custom_code_mode = '';
  760. private $types = array('', 'DISCOUNT', 'CASH', 'GROUPON', 'GIFT', 'GENERAL_COUPON', 'MEMBER_CARD', 'SCENIC_TICKET', 'MOVIE_TICKET');
  761. private $code_types = array(COUPON_CODE_TYPE_TEXT => 'CODE_TYPE_TEXT', COUPON_CODE_TYPE_QRCODE => 'CODE_TYPE_QRCODE', COUPON_CODE_TYPE_BARCODE => 'CODE_TYPE_BARCODE');
  762. public static function create($type) {
  763. $card_class = array(
  764. COUPON_TYPE_DISCOUNT => 'Discount',
  765. COUPON_TYPE_CASH => 'Cash',
  766. COUPON_TYPE_GENERAL => 'General',
  767. COUPON_TYPE_GIFT => 'Gift',
  768. COUPON_TYPE_GROUPON => 'Groupon',
  769. COUPON_TYPE_MEMBER => 'Member',
  770. );
  771. if (empty($card_class[$type])) {
  772. return error(-1, '卡券类型错误');
  773. }
  774. $classname = $card_class[$type] . 'Card';
  775. $card = new $classname();
  776. $card->type = $type;
  777. return $card;
  778. }
  779. public function setDateinfoRange($starttime, $endtime) {
  780. $this->date_info = array(
  781. 'type' => 'DATE_TYPE_FIX_TIME_RANGE', 'begin_timestamp' => strtotime($starttime),
  782. 'end_timestamp' => strtotime($endtime),
  783. );
  784. return true;
  785. }
  786. public function setDateinfoFix($begin, $term) {
  787. $this->date_info = array(
  788. 'type' => 'DATE_TYPE_FIX_TERM', 'fixed_term' => $term,
  789. 'fixed_begin_term' => $begin,
  790. );
  791. return true;
  792. }
  793. public function setCodetype($type) {
  794. $this->code_type = $this->code_types[$type];
  795. return true;
  796. }
  797. public function setLocation($location) {
  798. $store = pdo_getall('activity_stores', array('id' => $location), array('location_id'), 'location_id');
  799. if (!empty($store)) {
  800. $this->location_id_list = array_keys($store);
  801. }
  802. }
  803. public function setCenterMenu($title, $subtitle, $url) {
  804. $this->center_title = urlencode($title);
  805. $this->center_sub_title = urlencode($subtitle);
  806. $this->center_url = urlencode($url);
  807. return true;
  808. }
  809. public function setCustomMenu($title, $subtitle, $url) {
  810. $this->custom_url_name = urlencode($title);
  811. $this->custom_url_sub_title = urlencode($subtitle);
  812. $this->custom_url = urlencode($url);
  813. return true;
  814. }
  815. public function setPromotionMenu($title, $subtitle, $url) {
  816. $this->promotion_url_name = urlencode($title);
  817. $this->promotion_url_sub_title = urlencode($subtitle);
  818. $this->promotion_url = urlencode($url);
  819. return true;
  820. }
  821. public function setQuantity($quantity) {
  822. $this->sku = $sku = array('quantity' => intval($quantity));
  823. }
  824. public function validate() {
  825. if (empty($this->logo_url)) {
  826. return error(7, '未设置商户logo');
  827. }
  828. if (empty($this->brand_name)) {
  829. return error(8, '未设置商户名称');
  830. }
  831. if (empty($this->title)) {
  832. return error(9, '未设置卡券标题');
  833. }
  834. if (empty($this->service_phone)) {
  835. return error(11, '客服电话不能为空');
  836. }
  837. if (empty($this->description)) {
  838. return error(12, '使用须知不能为空');
  839. }
  840. return true;
  841. }
  842. private function getBaseinfo() {
  843. $fields = array(
  844. 'logo_url', 'brand_name', 'code_type', 'title', 'sub_title', 'color', 'notice',
  845. 'service_phone', 'description', 'date_info', 'sku', 'get_limit', 'use_custom_code',
  846. 'bind_openid', 'can_share', 'can_give_friend', 'location_id_list',
  847. 'center_title', 'center_sub_title', 'center_url',
  848. 'custom_url_name', 'custom_url', 'custom_url_sub_title',
  849. 'promotion_url_name', 'promotion_url', 'promotion_url_sub_title', 'source', 'get_custom_code_mode',
  850. );
  851. if (6 == $this->type) {
  852. $fields[] = 'need_push_on_view';
  853. $fields[] = 'pay_info';
  854. }
  855. $baseinfo = array();
  856. foreach ($this as $filed => $value) {
  857. if (in_array($filed, $fields)) {
  858. $baseinfo[$filed] = $value;
  859. }
  860. }
  861. return $baseinfo;
  862. }
  863. private function getAdvinfo() {
  864. return array();
  865. }
  866. public function getCardData() {
  867. $carddata = array(
  868. 'base_info' => $this->getBaseinfo(),
  869. );
  870. $carddata = array_merge($carddata, $this->getCardExtraData());
  871. $card = array(
  872. 'card' => array(
  873. 'card_type' => $this->types[$this->type],
  874. strtolower($this->types[$this->type]) => $carddata,
  875. ),
  876. );
  877. return $card;
  878. }
  879. public function getCardArray() {
  880. $data = array(
  881. 'card_id' => $this->card_id,
  882. 'type' => $this->type,
  883. 'logo_url' => urldecode($this->logo_url),
  884. 'code_type' => array_search($this->code_type, $this->code_types),
  885. 'brand_name' => $this->brand_name,
  886. 'title' => $this->title,
  887. 'sub_title' => $this->sub_title,
  888. 'color' => $this->color,
  889. 'notice' => $this->notice,
  890. 'description' => $this->description,
  891. 'quantity' => $this->sku['quantity'],
  892. 'use_custom_code' => intval($this->use_custom_code),
  893. 'bind_openid' => intval($this->bind_openid),
  894. 'can_share' => intval($this->can_share),
  895. 'can_give_friend' => intval($this->can_give_friend),
  896. 'get_limit' => $this->get_limit,
  897. 'service_phone' => $this->service_phone,
  898. 'status' => $this->status,
  899. 'is_display' => '1',
  900. 'is_selfconsume' => '0',
  901. 'promotion_url_name' => urldecode($this->promotion_url_name),
  902. 'promotion_url' => urldecode($this->promotion_url),
  903. 'promotion_url_sub_title' => urldecode($this->promotion_url_sub_title),
  904. 'source' => $this->source,
  905. );
  906. $data['date_info'] = array(
  907. 'time_type' => 'DATE_TYPE_FIX_TIME_RANGE' == $this->date_info['type'] ? 1 : 2,
  908. 'time_limit_start' => date('Y.m.d', $this->date_info['begin_timestamp']),
  909. 'time_limit_end' => date('Y.m.d', $this->date_info['end_timestamp']),
  910. 'deadline' => $this->date_info['fixed_begin_term'],
  911. 'limit' => $this->date_info['fixed_term'],
  912. );
  913. $data['date_info'] = iserializer($data['date_info']);
  914. $data['extra'] = iserializer($this->getCardExtraData());
  915. return $data;
  916. }
  917. }
  918. class MemberCard extends Card {
  919. public $background_pic_url = '';
  920. public $supply_bonus = true; public $bonus_rule = array(
  921. 'cost_money_unit' => 100, 'increase_bonus' => '', 'max_increase_bonus' => '', 'init_increase_bonus' => '', 'cost_bonus_unit' => '', 'reduce_money' => 100, 'least_money_to_use_bonus' => '', 'max_reduce_bonus' => '', ); public $supply_balance = true; public $prerogative = ''; public $auto_activate = false; public $custom_field1 = array('name_type' => 'FIELD_NAME_TYPE_COUPON', 'url' => '');
  922. public $activate_url = ''; public $wx_activate = false; public $bonus_url = ''; public $balance_url = ''; public $bonus_rules = ''; public $balance_rules = ''; public $custom_cell1 = array('name' => '账单', 'tips' => '', 'url' => 'http://06.we7.cc/app/index.php?i=76&c=mc&a=bond&do=credits&credittype=credit2&type=record&period=1&wxref=mp.weixin.qq.com#wechat_redirect');
  923. public $discount = ''; public $bonus_cleared = ''; public $format_type = true;
  924. public $grant_rate = '';
  925. public $offset_rate = '';
  926. public $offset_max = '';
  927. public $fields = array();
  928. public $grant = array();
  929. public $discount_type = '';
  930. public $nums_status = '';
  931. public $nums_text = '';
  932. public $times_status = '';
  933. public $times_text = '';
  934. public $params = '';
  935. public $html = '';
  936. public function GetCardArray() {
  937. return array(
  938. 'card_id' => $this->card_id,
  939. 'source' => $this->source,
  940. 'title' => $this->title,
  941. 'brand_name' => $this->brand_name,
  942. 'format_type' => $this->format_type,
  943. 'color' => $this->color,
  944. 'background' => $this->background_pic_url,
  945. 'logo' => $this->logo_url,
  946. 'description' => $this->description,
  947. 'grant_rate' => $this->grant_rate,
  948. 'offset_rate' => $this->offset_rate,
  949. 'offset_max' => $this->offset_max,
  950. 'fields' => $this->fields,
  951. 'grant' => $this->grant,
  952. 'discount_type' => $this->discount_type,
  953. 'nums_status' => $this->nums_status,
  954. 'nums_text' => $this->nums_text,
  955. 'times_status' => $this->times_status,
  956. 'times_text' => $this->times_text,
  957. 'params' => $this->params,
  958. 'html' => $this->html,
  959. 'notice' => $this->notice,
  960. 'quantity' => $this->sku['quantity'],
  961. 'least_money_to_use_bonus' => $this->bonus_rule['least_money_to_use_bonus'],
  962. 'max_increase_bonus' => $this->bonus_rule['max_increase_bonus'],
  963. );
  964. }
  965. public function getMemberCardUpdateArray() {
  966. $update['card_id'] = $this->card_id;
  967. $card = $this->getCardData();
  968. $update = array_merge($update, $card['card']);
  969. unset($update['card_type']);
  970. unset($update['member_card']['base_info']['source']);
  971. unset($update['member_card']['base_info']['sub_title']);
  972. unset($update['member_card']['base_info']['sku']);
  973. unset($update['member_card']['base_info']['use_custom_code']);
  974. unset($update['member_card']['base_info']['promotion_url_name']);
  975. unset($update['member_card']['base_info']['promotion_url']);
  976. unset($update['member_card']['base_info']['custom_url_name']);
  977. unset($update['member_card']['base_info']['custom_url']);
  978. unset($update['member_card']['base_info']['brand_name']);
  979. unset($update['member_card']['custom_cell1']);
  980. $update['member_card']['base_info']['promotion_url_name'] = urlencode('广播');
  981. $update['member_card']['base_info']['custom_url_name'] = urlencode('个人消息');
  982. $update['member_card']['base_info']['center_title'] = urlencode('付款');
  983. $update['member_card']['base_info']['title'] = urlencode($update['member_card']['base_info']['title']);
  984. $update['member_card']['base_info']['description'] = urlencode($update['member_card']['base_info']['description']);
  985. $update['member_card']['prerogative'] = urlencode($update['member_card']['prerogative']);
  986. return $update;
  987. }
  988. public function GetMemberCardArray() {
  989. $data = $this->getcardarray();
  990. return $data;
  991. }
  992. public function setBonusRule($cost_money_unit, $increase_bonus, $max_increase_bonus, $init_increase_bonus, $cost_bonus_unit, $reduce_money, $least_money_to_use_bonus, $max_reduce_bonus) {
  993. $this->bonus_rule = array(
  994. 'cost_money_unit' => $cost_money_unit,
  995. 'increase_bonus' => $increase_bonus,
  996. 'max_increase_bonus' => $max_increase_bonus,
  997. 'init_increase_bonus' => $init_increase_bonus,
  998. 'cost_bonus_unit' => $cost_bonus_unit,
  999. 'reduce_money' => $reduce_money,
  1000. 'least_money_to_use_bonus' => $least_money_to_use_bonus,
  1001. 'max_reduce_bonus' => $max_reduce_bonus,
  1002. );
  1003. return true;
  1004. }
  1005. public function setCustomCell($name, $tips, $url) {
  1006. $this->custom_cell1 = array(
  1007. 'name' => $name,
  1008. 'tips' => $tips,
  1009. 'url' => $url,
  1010. );
  1011. return true;
  1012. }
  1013. public function setCustomField($name_type, $url, $num) {
  1014. $array = array(
  1015. 'name_type' => $name_type,
  1016. 'url' => $url,
  1017. );
  1018. if (1 == $num) {
  1019. $this->custom_field1 = $array;
  1020. }
  1021. if (2 == $num) {
  1022. $this->custom_field2 = $array;
  1023. }
  1024. if (3 == $num) {
  1025. $this->custom_field3 = $array;
  1026. }
  1027. return true;
  1028. }
  1029. public function validate() {
  1030. $error = parent::validate();
  1031. if (is_error($error) && 11 != $error['errno']) {
  1032. return $error;
  1033. }
  1034. if (!empty($this->supply_bonus)) {
  1035. if (empty($this->bonus_rule['cost_money_unit'])) {
  1036. return error(13, '未填写积分说明中的消费金额');
  1037. }
  1038. if (empty($this->bonus_rule['increase_bonus'])) {
  1039. return error(14, '未填写积分说明中的对应增加金额');
  1040. }
  1041. if (empty($this->bonus_rule['max_increase_bonus'])) {
  1042. return error(15, '未填写积分说明中的用户单次可获取的积分上限');
  1043. }
  1044. if (empty($this->bonus_rule['init_increase_bonus'])) {
  1045. return error(16, '未填写积分说明中的初始设置积分');
  1046. }
  1047. if (empty($this->bonus_rule['cost_bonus_unit'])) {
  1048. return error(17, '未填写积分说明中的每次使用积分');
  1049. }
  1050. if (empty($this->bonus_rule['reduce_money'])) {
  1051. return error(18, '未填写积分说明中的会员卡可抵扣多少元');
  1052. }
  1053. if (empty($this->bonus_rule['least_money_to_use_bonus'])) {
  1054. return error(19, '未填写积分说明中的满xx元可用');
  1055. }
  1056. if (empty($this->bonus_rule['max_reduce_bonus'])) {
  1057. return error(20, '未填写积分说明中的单笔最多使用xx积分');
  1058. }
  1059. }
  1060. if (!empty($this->custom_cell1['name']) || !empty($this->custom_cell1['tips']) || !empty($this->custom_cell1['url'])) {
  1061. if (empty($this->custom_cell1['name'])) {
  1062. return error(21, '未填写入口名称');
  1063. }
  1064. if (empty($this->custom_cell1['url'])) {
  1065. return error(23, '未填写入口跳转链接');
  1066. }
  1067. }
  1068. if (empty($this->prerogative)) {
  1069. return error(24, '未填写会员卡特权说明');
  1070. }
  1071. if (empty($this->wx_activate) && empty($this->activate_url)) {
  1072. return error(25, '未填写激活会员卡url');
  1073. }
  1074. return true;
  1075. }
  1076. public function getCardExtraData() {
  1077. return array(
  1078. 'background_pic_url' => $this->background_pic_url,
  1079. 'supply_bonus' => $this->supply_bonus,
  1080. 'bonus_rule' => $this->bonus_rule,
  1081. 'supply_balance' => $this->supply_balance,
  1082. 'prerogative' => $this->prerogative,
  1083. 'auto_activate' => $this->auto_activate,
  1084. 'custom_field1' => $this->custom_field1,
  1085. 'activate_url' => $this->activate_url,
  1086. 'wx_activate' => $this->wx_activate,
  1087. 'bonus_url' => $this->bonus_url,
  1088. 'balance_url' => $this->balance_url,
  1089. 'bonus_rules' => $this->bonus_rules,
  1090. 'balance_rules' => $this->balance_rules,
  1091. 'custom_cell1' => $this->custom_cell1,
  1092. 'discount' => $this->discount,
  1093. 'bonus_cleared' => $this->bonus_cleared,
  1094. );
  1095. }
  1096. }
  1097. class DiscountCard extends Card {
  1098. public $discount = 0;
  1099. public function validate() {
  1100. $error = parent::validate();
  1101. if (is_error($error)) {
  1102. return $error;
  1103. }
  1104. if (empty($this->discount)) {
  1105. return error(1, '未设置折扣券折扣');
  1106. }
  1107. return true;
  1108. }
  1109. public function getCardExtraData() {
  1110. return array(
  1111. 'discount' => $this->discount,
  1112. );
  1113. }
  1114. }
  1115. class CashCard extends Card {
  1116. public $least_cost = 0; public $reduce_cost = 0;
  1117. public function validate() {
  1118. $error = parent::validate();
  1119. if (is_error($error)) {
  1120. return $error;
  1121. }
  1122. if (!isset($this->least_cost)) {
  1123. return error(2, '未设置代金券起用金额');
  1124. }
  1125. if (empty($this->least_cost)) {
  1126. return error(3, '未设置代金券减免金额');
  1127. }
  1128. return true;
  1129. }
  1130. public function getCardExtraData() {
  1131. return array(
  1132. 'least_cost' => $this->least_cost,
  1133. 'reduce_cost' => $this->reduce_cost,
  1134. );
  1135. }
  1136. }
  1137. class GiftCard extends Card {
  1138. public $gift = '';
  1139. public function validate() {
  1140. $error = parent::validate();
  1141. if (is_error($error)) {
  1142. return $error;
  1143. }
  1144. if (empty($this->gift)) {
  1145. return error(4, '未设置礼品券兑换内容');
  1146. }
  1147. return true;
  1148. }
  1149. public function getCardExtraData() {
  1150. return array(
  1151. 'gift' => $this->gift,
  1152. );
  1153. }
  1154. }
  1155. class GrouponCard extends Card {
  1156. public $deal_detail = '';
  1157. public function validate() {
  1158. $error = parent::validate();
  1159. if (is_error($error)) {
  1160. return $error;
  1161. }
  1162. if (empty($this->deal_detail)) {
  1163. return error(5, '未设置团购券详情内容');
  1164. }
  1165. return true;
  1166. }
  1167. public function getCardExtraData() {
  1168. return array(
  1169. 'deal_detail' => $this->deal_detail,
  1170. );
  1171. }
  1172. }
  1173. class GeneralCard extends Card {
  1174. public $default_detail = '';
  1175. public function validate() {
  1176. $error = parent::validate();
  1177. if (is_error($error)) {
  1178. return $error;
  1179. }
  1180. if (empty($this->default_detail)) {
  1181. return error(6, '未设置优惠券优惠详情');
  1182. }
  1183. return true;
  1184. }
  1185. public function getCardExtraData() {
  1186. return array(
  1187. 'default_detail' => $this->default_detail,
  1188. );
  1189. }
  1190. }