UserModel.class.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Seller\Model;
  10. class UserModel{
  11. public function get_member_count($where='')
  12. {
  13. $total = M('lionfish_comshop_member')->where("1 ".$where)->count();
  14. return $total;
  15. }
  16. //------------------------------------------------begin
  17. public function delete_use_auto_template()
  18. {
  19. @set_time_limit(0);
  20. $config_data = array();
  21. $weixin_config = array();
  22. $weixin_config['appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  23. $weixin_config['appscert'] = D('Home/Front')->get_config_by_name('wepro_appsecret');
  24. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'], $weixin_config['appscert']);
  25. $re_access_token = $jssdk->getweAccessToken();
  26. $send_url ="https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token={$re_access_token}";
  27. $data = array();
  28. $data['offset'] = 0;
  29. $data['count'] = 20;
  30. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  31. $result = json_decode($result_json, true);
  32. $del_title_arr = array('申请成功提醒','退款成功通知','订单支付成功通知','订单发货提醒','核销成功通知','提现到账通知');
  33. $del_template_arr = array();
  34. if($result['errcode'] == 0)
  35. {
  36. foreach( $result['list'] as $val )
  37. {
  38. if( in_array($val['title'], $del_title_arr) )
  39. {
  40. $del_template_arr[] = $val['template_id'];
  41. }
  42. }
  43. }
  44. if( !empty($del_template_arr) )
  45. {
  46. foreach($del_template_arr as $vv)
  47. {
  48. $send_url ="https://api.weixin.qq.com/cgi-bin/wxopen/template/del?access_token={$re_access_token}";
  49. $data = array();
  50. $data['template_id'] = $vv;
  51. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  52. }
  53. }
  54. //https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token=ACCESS_TOKEN
  55. }
  56. public function mange_template_auto()
  57. {
  58. $this->delete_use_auto_template();
  59. @set_time_limit(0);
  60. $config_data = array();
  61. $weixin_config = array();
  62. $weixin_config['appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  63. $weixin_config['appscert'] = D('Home/Front')->get_config_by_name('wepro_appsecret');
  64. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'], $weixin_config['appscert']);
  65. $re_access_token = $jssdk->getweAccessToken();
  66. $send_url ="https://api.weixin.qq.com/cgi-bin/wxopen/template/add?access_token={$re_access_token}";
  67. //-----------------团长申请成功发送通知------------------------
  68. $data = array();
  69. $data['id'] = 'AT0197';
  70. $data['keyword_id_list'] = array(1,13,3,6,77,44,50);
  71. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  72. $result = json_decode($result_json, true);
  73. if($result['errcode'] == 0)
  74. {
  75. $config_data['weprogram_template_apply_community'] = $result['template_id'];
  76. }
  77. //------------------订单支付成功通知----------------------------
  78. $data = array();
  79. $data['id'] = 'AT0009';
  80. $data['keyword_id_list'] = array(1,13,10,11,20);
  81. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  82. $result = json_decode($result_json, true);
  83. if($result['errcode'] == 0)
  84. {
  85. $config_data['weprogram_template_pay_order'] = $result['template_id'];
  86. }
  87. //---------------------------------------------------------------
  88. //------------------订单发货提醒---------------------------------
  89. $data = array();
  90. $data['id'] = 'AT0007';
  91. $data['keyword_id_list'] = array(5,7,47,34,11);
  92. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  93. $result = json_decode($result_json, true);
  94. if($result['errcode'] == 0)
  95. {
  96. $config_data['weprogram_template_send_order'] = $result['template_id'];
  97. }
  98. //---------------------------------------------------------------
  99. //------------------核销成功通知---------------------------------
  100. $data = array();
  101. $data['id'] = 'AT0423';
  102. $data['keyword_id_list'] = array(5,2,6,3,9);
  103. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  104. $result = json_decode($result_json, true);
  105. if($result['errcode'] == 0)
  106. {
  107. $config_data['weprogram_template_hexiao_success'] = $result['template_id'];
  108. }
  109. //---------------------------------------------------------------
  110. //------------------退款成功通知---------------------------------
  111. $data = array();
  112. $data['id'] = 'AT0787';
  113. $data['keyword_id_list'] = array(8,13,14,17,7,18);
  114. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  115. $result = json_decode($result_json, true);
  116. if($result['errcode'] == 0)
  117. {
  118. $config_data['weprogram_template_refund_order'] = $result['template_id'];
  119. }
  120. //---------------------------------------------------------------
  121. //------------------提现到账通知---------------------------------
  122. $data = array();
  123. $data['id'] = 'AT0830';
  124. $data['keyword_id_list'] = array(5,3,1,6,8,11,2);
  125. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  126. $result = json_decode($result_json, true);
  127. if($result['errcode'] == 0)
  128. {
  129. $config_data['weprogram_template_apply_tixian'] = $result['template_id'];
  130. }
  131. //---------------------------------------------------------------
  132. //------------------拼团开团通知---------------------------------
  133. $data = array();
  134. $data['id'] = 'AT0541';
  135. $data['keyword_id_list'] = array(15,1,10,26,24);
  136. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  137. $result = json_decode($result_json, true);
  138. if($result['errcode'] == 0)
  139. {
  140. $config_data['weprogram_template_open_tuan'] = $result['template_id'];
  141. }
  142. //---------------------------------------------------------------
  143. //------------------参团通知---------------------------------
  144. $data = array();
  145. $data['id'] = 'AT0933';
  146. $data['keyword_id_list'] = array(3,18,27);
  147. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  148. $result = json_decode($result_json, true);
  149. if($result['errcode'] == 0)
  150. {
  151. $config_data['weprogram_template_take_tuan'] = $result['template_id'];
  152. }
  153. //------------------拼团成功通知---------------------------------
  154. $data = array();
  155. $data['id'] = 'AT0051';
  156. $data['keyword_id_list'] = array(13,6,12);
  157. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  158. $result = json_decode($result_json, true);
  159. if($result['errcode'] == 0)
  160. {
  161. $config_data['weprogram_template_pin_tuansuccess'] = $result['template_id'];
  162. }
  163. //---------------------------------------------------------------
  164. D('Seller/Config')->update($config_data);
  165. //AT0197 申请时间 所在地 服务地址 姓名 手机号 申请状态 同意时间1
  166. }
  167. //-----------------------------------------------end
  168. //--------begin
  169. /**
  170. 更改会员余额
  171. **/
  172. public function sendMemberMoneyChange($member_id, $num, $changetype, $remark='')
  173. {
  174. $member_info = M('lionfish_comshop_member')->field('account_money')->where( array('member_id' => $member_id) )->find();
  175. $account_money = $member_info['account_money'];
  176. $flow_data = array();
  177. $flow_data['member_id'] = $member_id;
  178. $flow_data['trans_id'] = '';
  179. //0,未支付,1已支付,3余额付款,4退款到余额,5后台充值 6 后台扣款
  180. //增加
  181. if($changetype == 0)
  182. {
  183. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set account_money = account_money+ ".$num ." where member_id=".$member_id;
  184. $flow_data['state'] = '5';
  185. }else if($changetype == 1)
  186. {
  187. //减少
  188. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set account_money = account_money - ".$num ." where member_id=".$member_id;
  189. $flow_data['state'] = '8';
  190. }else if($changetype == 2){
  191. //最终积分
  192. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set account_money = ".$num ." where member_id=".$member_id;
  193. if($account_money >= $num)
  194. {
  195. $flow_data['state'] = '8';
  196. $num = $account_money - $num;
  197. }else{
  198. $flow_data['state'] = '5';
  199. $num = $num - $account_money;
  200. }
  201. }
  202. else if( $changetype == 9 )
  203. {
  204. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set account_money = account_money+ ".$num ." where member_id=".$member_id;
  205. $flow_data['state'] = '9';
  206. }
  207. else if( $changetype == 10 )
  208. {
  209. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set account_money = account_money+ ".$num ." where member_id=".$member_id;
  210. $flow_data['state'] = '10';
  211. }else if( $changetype == 11 )
  212. {//拼团佣金
  213. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set account_money = account_money+ ".$num ." where member_id=".$member_id;
  214. $flow_data['state'] = '11';
  215. }else if( $changetype == 12 )
  216. {//配送佣金
  217. $account_money = $account_money + $num;
  218. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set account_money = ".$account_money ." where member_id=".$member_id;
  219. $flow_data['state'] = '12';
  220. }
  221. $flow_data['money'] = $num;
  222. $flow_data['remark'] = $remark;
  223. $flow_data['charge_time'] = time();
  224. $flow_data['add_time'] = time();
  225. M()->execute( $up_sql );
  226. $member_info2 = M('lionfish_comshop_member')->field('account_money')->where( array('member_id' => $member_id) )->find();
  227. $flow_data['operate_end_yuer'] = $member_info2['account_money'];
  228. M('lionfish_comshop_member_charge_flow')->add($flow_data);
  229. }
  230. /**
  231. 更新会员积分
  232. **/
  233. public function sendMemberPointChange($member_id,$num, $changetype ,$remark ='', $ch_type='system_add')
  234. {
  235. $member_info = M('lionfish_comshop_member')->field('score')->where( array('member_id' => $member_id) )->find();
  236. $member_score = $member_info['score'];
  237. $flow_data = array();
  238. $flow_data['member_id'] = $member_id;
  239. $flow_data['type'] = $ch_type;
  240. $flow_data['order_id'] = '0';
  241. //增加
  242. if($changetype == 0)
  243. {
  244. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set score = score+ ".$num ." where member_id=".$member_id;
  245. $flow_data['in_out'] = 'in';
  246. }else if($changetype == 1)
  247. {
  248. //减少
  249. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set score = score - ".$num ." where member_id=".$member_id;
  250. $flow_data['in_out'] = 'out';
  251. }else if($changetype == 2){
  252. //最终积分
  253. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set score = ".$num ." where member_id=".$member_id;
  254. if($member_score >= $num)
  255. {
  256. $flow_data['in_out'] = 'out';
  257. $num = $member_score - $num;
  258. }else{
  259. $flow_data['in_out'] = 'in';
  260. $num = $num - $member_score;
  261. }
  262. }
  263. //after_operate_score
  264. $flow_data['score'] = $num;
  265. $flow_data['state'] = 1;
  266. $flow_data['remark'] = $remark;
  267. $flow_data['addtime'] = time();
  268. M()->execute( $up_sql );
  269. $info = M('lionfish_comshop_member')->field('score')->where( array('member_id' => $member_id ) )->find();
  270. $flow_data['after_operate_score'] = $info['score'];
  271. M('lionfish_comshop_member_integral_flow')->add($flow_data);
  272. }
  273. //--------end
  274. /**
  275. * [addTemplates (订阅消息)
  276. * @param [type] tid [模板标题id]
  277. * @param [type] kidList [模板关键词列表]
  278. * @param [type] sceneDesc [服务场景描述]
  279. */
  280. //订阅信息一键获取
  281. public function mange_subscribetemplate_auto()
  282. {
  283. $this->delete_use_auto_template();
  284. @set_time_limit(0);
  285. $config_data = array();
  286. $weixin_config = array();
  287. $weixin_config['appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  288. $weixin_config['appscert'] = D('Home/Front')->get_config_by_name('wepro_appsecret');
  289. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'], $weixin_config['appscert']);
  290. $re_access_token = $jssdk->getweAccessToken($uniacid);
  291. //判断用户的小程序类目中,是否有咱们需要的小程序类目,如果没有,给他提示出来缺什么类目。
  292. $category_url = "https://api.weixin.qq.com/wxaapi/newtmpl/getcategory?access_token={$re_access_token}";
  293. $result_category =array();
  294. $result_category_json = $this->curl_category($category_url);
  295. $result_category = json_decode($result_category_json, true);
  296. // {"id":670,"name":"线下超市/便利店"},{"id":307,"name":"服装/鞋/箱包"}
  297. $name = array_column($result_category['data'], 'name');
  298. $found_supermarket = in_array("线下超市/便利店", $name);
  299. $found_clothing = in_array("服装/鞋/箱包", $name);
  300. if( empty($found_supermarket) && empty($found_clothing) ){
  301. if(empty($found_supermarket)){
  302. //show_json(0, array('message' => '请在微信公众平台添加 "线下超市/便利店" 类目') );
  303. show_json(0, array('message' => '请在微信公众平台添加商家自营--->服装/鞋/箱包 、 生活服务--->百货/线下超市/便利店') );
  304. die();
  305. }
  306. if(empty($found_clothing)){
  307. //show_json(0, array('message' => '请在微信公众平台添加 "服装/鞋/箱包" 类目' ) );
  308. show_json(0, array('message' => '请在微信公众平台添加商家自营--->服装/鞋/箱包 、 生活服务--->百货/线下超市/便利店' ) );
  309. die();
  310. }
  311. }else{
  312. //删除
  313. $del_url = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token={$re_access_token}";
  314. $send_url ="https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token={$re_access_token}";
  315. //https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token=
  316. //------------------订单支付成功通知----------------------------
  317. $data = array();
  318. $data['tid'] = '1253';
  319. $data['kidList'] = array(1,2,3,4,7);
  320. $data['sceneDesc'] ='用户支付订单';
  321. //先删除再添加
  322. $arr = array();
  323. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pay_order');
  324. if(!empty($arr['priTmplId'])){
  325. $result_del_json = $this->curl_datas($del_url,$arr);
  326. $result_del = json_decode($result_del_json, true);
  327. }
  328. //$result_json = $this->curl_datas($send_url, json_encode($data));
  329. $result_json = $this->curl_datas($send_url,$data);
  330. $result = json_decode($result_json, true);
  331. if($result['errcode'] == 0)
  332. {
  333. $config_data['weprogram_subtemplate_pay_order'] = $result['priTmplId'];
  334. }
  335. //---------------------------------------------------------------
  336. //------------------订单发货提醒---------------------------------
  337. $data = array();
  338. $data['tid'] = '855';
  339. $data['kidList'] = array(1,2,3,6,9);
  340. $data['sceneDesc'] ='用户订单发货';
  341. //先删除再添加
  342. $arr = array();
  343. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_send_order');
  344. if(!empty($arr['priTmplId'])){
  345. $result_del_json = $this->curl_datas($del_url,$arr);
  346. $result_del = json_decode($result_del_json, true);
  347. }
  348. $result_json = $this->curl_datas($send_url,$data);
  349. $result = json_decode($result_json, true);
  350. if($result['errcode'] == 0)
  351. {
  352. $config_data['weprogram_subtemplate_send_order'] = $result['priTmplId'];
  353. }
  354. //---------------------------------------------------------------
  355. //------------------核销成功通知---------------------------------
  356. $data = array();
  357. $data['tid'] = '3116';
  358. $data['kidList'] = array(2,3,4);
  359. $data['sceneDesc'] ='商家核销';
  360. //先删除再添加
  361. $arr = array();
  362. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_hexiao_success');
  363. if(!empty($arr['priTmplId'])){
  364. $result_del_json = $this->curl_datas($del_url,$arr);
  365. $result_del = json_decode($result_del_json, true);
  366. }
  367. $result_json = $this->curl_datas($send_url,$data);
  368. $result = json_decode($result_json, true);
  369. if($result['errcode'] == 0)
  370. {
  371. $config_data['weprogram_subtemplate_hexiao_success'] = $result['priTmplId'];
  372. }
  373. //---------------------------------------------------------------
  374. /*------------------退款成功通知---------------------------------
  375. $data = array();
  376. $data['tid'] = 'AT0197';
  377. $data['kidList'] = array(1,13,3,6,77,44,50);
  378. $result_json = $this->curl_datas($send_url,$data);
  379. $result = json_decode($result_json, true);
  380. if($result['errcode'] == 0)
  381. {
  382. $config_data['weprogram_subtemplate_refund_order'] = $result['template_id'];
  383. }
  384. //--------------------------------------------------------------- */
  385. //-----------------团长申请成功发送通知------------------------
  386. $data = array();
  387. $data['tid'] = '3635';
  388. $data['kidList'] = array(1,2,3,4,5);
  389. $data['sceneDesc'] ='团长申请成功';
  390. //先删除再添加
  391. $arr = array();
  392. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_community');
  393. if(!empty($arr['priTmplId'])){
  394. $result_del_json = $this->curl_datas($del_url,$arr);
  395. $result_del = json_decode($result_del_json, true);
  396. }
  397. $result_json = $this->curl_datas($send_url,$data);
  398. $result = json_decode($result_json, true);
  399. if($result['errcode'] == 0)
  400. {
  401. $config_data['weprogram_subtemplate_apply_community'] = $result['priTmplId'];
  402. }
  403. //---------------------------------------------------------------
  404. //------------------拼团开团通知---------------------------------
  405. $data = array();
  406. $data['tid'] = '3185';
  407. $data['kidList'] = array(1,2,3,5);
  408. $data['sceneDesc'] ='团长开团';
  409. //先删除再添加
  410. $arr = array();
  411. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_open_tuan');
  412. if(!empty($arr['priTmplId'])){
  413. $result_del_json = $this->curl_datas($del_url,$arr);
  414. $result_del = json_decode($result_del_json, true);
  415. }
  416. $result_json = $this->curl_datas($send_url,$data);
  417. $result = json_decode($result_json, true);
  418. if($result['errcode'] == 0)
  419. {
  420. $config_data['weprogram_subtemplate_open_tuan'] = $result['priTmplId'];
  421. }
  422. //---------------------------------------------------------------
  423. //------------------参团通知-------------------------------------
  424. $data = array();
  425. $data['tid'] = '3653';
  426. $data['kidList'] = array(1,2,3);
  427. $data['sceneDesc'] ='团员参团';
  428. //先删除再添加
  429. $arr = array();
  430. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_take_tuan');
  431. if(!empty($arr['priTmplId'])){
  432. $result_del_json = $this->curl_datas($del_url,$arr);
  433. $result_del = json_decode($result_del_json, true);
  434. }
  435. $result_json = $this->curl_datas($send_url,$data);
  436. $result = json_decode($result_json, true);
  437. if($result['errcode'] == 0)
  438. {
  439. $config_data['weprogram_subtemplate_take_tuan'] = $result['priTmplId'];
  440. }
  441. //---------------------------------------------------------------
  442. //------------------拼团成功通知---------------------------------
  443. $data = array();
  444. $data['tid'] = '980';
  445. $data['kidList'] = array(1,3,7);
  446. $data['sceneDesc'] ='拼团成功';
  447. //先删除再添加
  448. $arr = array();
  449. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pin_tuansuccess');
  450. if(!empty($arr['priTmplId'])){
  451. $result_del_json = $this->curl_datas($del_url,$arr);
  452. $result_del = json_decode($result_del_json, true);
  453. }
  454. $result_json = $this->curl_datas($send_url,$data);
  455. $result = json_decode($result_json, true);
  456. if($result['errcode'] == 0)
  457. {
  458. $config_data['weprogram_subtemplate_pin_tuansuccess'] = $result['priTmplId'];
  459. }
  460. //---------------------------------------------------------------
  461. //------------------提现到账通知---------------------------------
  462. $data = array();
  463. $data['tid'] = '2001';
  464. $data['kidList'] = array(1,2,3,4);
  465. $data['sceneDesc'] ='供应商申请提现';
  466. //先删除再添加
  467. $arr = array();
  468. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_tixian');
  469. if(!empty($arr['priTmplId'])){
  470. $result_del_json = $this->curl_datas($del_url,$arr);
  471. $result_del = json_decode($result_del_json, true);
  472. }
  473. $result_json = $this->curl_datas($send_url,$data);
  474. $result = json_decode($result_json, true);
  475. if($result['errcode'] == 0)
  476. {
  477. $config_data['weprogram_subtemplate_apply_tixian'] = $result['priTmplId'];
  478. }
  479. //---------------------------------------------------------------
  480. //-----------------预售商品到货通知
  481. $data = array();
  482. $data['tid'] = '339';
  483. $data['kidList'] = array(2,3,7);
  484. $data['sceneDesc'] ='预定到货通知';
  485. //先删除再添加
  486. $arr = array();
  487. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_presale_ordercan_continuepay');
  488. if(!empty($arr['priTmplId'])){
  489. $result_del_json = $this->curl_datas($del_url,$arr);
  490. $result_del = json_decode($result_del_json, true);
  491. }
  492. $result_json = $this->curl_datas($send_url,$data);
  493. $result = json_decode($result_json, true);
  494. if($result['errcode'] == 0)
  495. {
  496. $config_data['weprogram_subtemplate_presale_ordercan_continuepay'] = $result['priTmplId'];
  497. }
  498. //---------------------------------------------------------------
  499. D('Seller/Config')->update($config_data);
  500. }
  501. }
  502. function curl_category($url)
  503. {
  504. $ch = curl_init();
  505. //取数据的地址
  506. curl_setopt($ch, CURLOPT_URL, $url);
  507. //传输为post
  508. if(defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
  509. curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
  510. }
  511. //隐藏返回结果
  512. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  513. curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
  514. curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
  515. //执行
  516. $handles = curl_exec($ch);
  517. //断开
  518. curl_close($ch);
  519. return $handles;
  520. }
  521. /**
  522. 发送订阅小程序消息
  523. **/
  524. function send_subscript_msg( $template_data,$url,$pagepath,$to_openid,$template_id, $delay_time = 0 )
  525. {
  526. $weixin_config = array();
  527. $weixin_config['appid'] = D('Seller/Front')->get_config_by_name('wepro_appid');
  528. $weixin_config['appscert'] = D('Seller/Front')->get_config_by_name('wepro_appsecret');
  529. $siteroot = D('Seller/Front')->get_config_by_name('shop_domain');
  530. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'], $weixin_config['appscert']);
  531. $re_access_token = $jssdk->getweAccessToken();
  532. $template = array(
  533. 'touser' => $to_openid,
  534. 'template_id' => $template_id,
  535. 'page' => $pagepath,
  536. 'data' => $template_data
  537. );
  538. if($delay_time > 0)
  539. sleep($delay_time);
  540. $send_url ="https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={$re_access_token}";
  541. $result = $this->sendhttps_post($send_url, json_encode($template));
  542. //log
  543. $ck_json_arr = json_decode($result,true);
  544. return $ck_json_arr;
  545. }
  546. /**
  547. 发送小程序模板消息
  548. **/
  549. function send_wxtemplate_msg($template_data,$url,$pagepath,$to_openid,$template_id,$form_id='1',$uniacid=0,$wx_template_data = array() ,$delay_time = 0)
  550. {
  551. $weixin_config = array();
  552. $weixin_config['appid'] = D('Seller/Front')->get_config_by_name('wepro_appid');
  553. $weixin_config['appscert'] = D('Seller/Front')->get_config_by_name('wepro_appsecret');
  554. $siteroot = D('Seller/Front')->get_config_by_name('shop_domain');
  555. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'], $weixin_config['appscert']);
  556. $re_access_token = $jssdk->getweAccessToken();
  557. $template = array(
  558. 'touser' => $to_openid,
  559. 'template_id' => $template_id,
  560. 'form_id' => $form_id,
  561. 'page' => $pagepath,
  562. 'data' => $template_data
  563. );
  564. if(!empty($wx_template_data))
  565. {
  566. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token={$re_access_token}";
  567. $new_template = array();
  568. $new_template['touser'] = $to_openid;
  569. $new_template['mp_template_msg'] = array(
  570. 'appid' => $wx_template_data['appid'],
  571. 'template_id' => $wx_template_data['template_id'],
  572. 'url' => $siteroot,
  573. 'miniprogram' => array(
  574. 'appid' => $weixin_config['appid'],
  575. 'pagepath' => $wx_template_data['pagepath']
  576. ),
  577. 'data' => $wx_template_data['data']
  578. );
  579. $result = $this->sendhttps_post($url, json_encode($new_template));
  580. $result_arr = json_decode($result, true);
  581. if( $result_arr['errcode'] > 0 )
  582. {
  583. $new_template['mp_template_msg'] = array(
  584. 'appid' => $wx_template_data['appid'],
  585. 'template_id' => $wx_template_data['template_id'],
  586. 'url' => $siteroot,
  587. 'miniprogram' => array(
  588. 'appid' => $weixin_config['appid'],
  589. 'page' => $wx_template_data['pagepath']
  590. ),
  591. 'data' => $wx_template_data['data']
  592. );
  593. $result = $this->sendhttps_post($url, json_encode($new_template));
  594. }
  595. //$result = json_encode($result);
  596. }
  597. if( !empty($template_data) )
  598. {
  599. if($delay_time > 0)
  600. sleep($delay_time);
  601. $send_url ="https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token={$re_access_token}";
  602. $result = $this->sendhttps_post($send_url, json_encode($template));
  603. }
  604. return json_decode($result,true);
  605. }
  606. function curl_datas($url,$data,$timeout=30)
  607. {
  608. $ch = curl_init();
  609. //取数据的地址
  610. curl_setopt($ch, CURLOPT_URL, $url);
  611. //传输为post
  612. if(defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
  613. curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
  614. }
  615. curl_setopt($ch, CURLOPT_POST, true);
  616. //传输数据(这里data是二维数组,一定要加http_build_query,不然会报错)
  617. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  618. //隐藏返回结果
  619. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  620. //限制时间
  621. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  622. //https支持
  623. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//这个是重点。
  624. //执行
  625. $handles = curl_exec($ch);
  626. //断开
  627. curl_close($ch);
  628. return $handles;
  629. }
  630. public function just_send_wxtemplate($to_openid, $uniacid=0,$wx_template_data = array() )
  631. {
  632. $weixin_config = array();
  633. $weixin_config['appid'] = D('Seller/Front')->get_config_by_name('wepro_appid');
  634. $weixin_config['appscert'] = D('Seller/Front')->get_config_by_name('wepro_appsecret');
  635. $siteroot = D('Seller/Front')->get_config_by_name('shop_domain');
  636. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'], $weixin_config['appscert']);
  637. $re_access_token = $jssdk->getweAccessToken();
  638. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token={$re_access_token}";
  639. $new_template = array();
  640. $new_template['touser'] = $to_openid;
  641. $new_template['mp_template_msg'] = array(
  642. 'appid' => $wx_template_data['appid'],
  643. 'template_id' => $wx_template_data['template_id'],
  644. 'url' => $siteroot,
  645. 'miniprogram' => array(
  646. 'appid' => $weixin_config['appid'],
  647. 'pagepath' => $wx_template_data['pagepath']
  648. ),
  649. 'data' => $wx_template_data['data']
  650. );
  651. $result = $this->sendhttps_post($url, json_encode($new_template));
  652. }
  653. function sendhttp_get($url)
  654. {
  655. $curl = curl_init();
  656. curl_setopt($curl,CURLOPT_URL,$url);
  657. curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,FALSE);
  658. curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,FALSE);
  659. curl_setopt($curl,CURLOPT_POST,1);
  660. curl_setopt($curl,CURLOPT_POSTFIELDS,array());
  661. curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
  662. $result = curl_exec($curl);
  663. curl_close($curl);
  664. return $result;
  665. }
  666. function sendhttps_post($url,$data)
  667. {
  668. $curl = curl_init();
  669. curl_setopt($curl,CURLOPT_URL,$url);
  670. curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,FALSE);
  671. curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,FALSE);
  672. curl_setopt($curl,CURLOPT_POST,1);
  673. curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
  674. curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
  675. $result = curl_exec($curl);
  676. if(curl_errno($curl)){
  677. return 'Errno'.curl_error($curl);
  678. }
  679. curl_close($curl);
  680. return $result;
  681. }
  682. }
  683. ?>