WeprogramController.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Seller\Controller;
  10. class WeprogramController extends CommonController{
  11. protected function _initialize(){
  12. parent::_initialize();
  13. //'pinjie' => '拼团介绍',
  14. }
  15. public function index()
  16. {
  17. $type = I('request.type');
  18. $type = isset($type) && !empty($type) ? $type : 1;
  19. if (IS_POST) {
  20. $data = I('request.parameter');
  21. $param['wepro_share_title'] = trim($data['wepro_share_title']);
  22. $param['wepro_appid'] = trim($data['wepro_appid']);
  23. $param['wepro_appsecret'] = trim($data['wepro_appsecret']);
  24. $param['wepro_partnerid'] = trim($data['wepro_partnerid']);
  25. $param['wepro_key'] = trim($data['wepro_key']);
  26. $param['is_open_yinpay'] =$data['is_open_yinpay'] ? trim($data['is_open_yinpay']) : 0;
  27. if(!empty($data['wechat_apiclient_cert_pem'])){ $param['wechat_apiclient_cert_pem'] = trim($data['wechat_apiclient_cert_pem']);}
  28. if(!empty($data['wechat_apiclient_key_pem'])){ $param['wechat_apiclient_key_pem'] = trim($data['wechat_apiclient_key_pem']);}
  29. if(!empty($data['sup_wechat_apiclient_cert_pem'])){ $param['sup_wechat_apiclient_cert_pem'] = trim($data['sup_wechat_apiclient_cert_pem']);}
  30. if(!empty($data['sup_wechat_apiclient_key_pem'])){ $param['sup_wechat_apiclient_key_pem'] = trim($data['sup_wechat_apiclient_key_pem']);}
  31. if(!empty($data['wepro_sub_mch_id'])){ $param['wepro_sub_mch_id'] = trim($data['wepro_sub_mch_id']);}
  32. if(!empty($data['wepro_fuwu_appid'])){ $param['wepro_fuwu_appid'] = trim($data['wepro_fuwu_appid']);}
  33. if(!empty($data['wepro_fuwu_partnerid'])){ $param['wepro_fuwu_partnerid'] = trim($data['wepro_fuwu_partnerid']);}
  34. if(!empty($data['sup_wepro_key'])){ $param['sup_wepro_key'] = trim($data['sup_wepro_key']);}
  35. D('Seller/Config')->update($param);
  36. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  37. }
  38. $data = D('Seller/Config')->get_all_config();
  39. $this->data = $data;
  40. $this->type = $type;
  41. $this->display();
  42. }
  43. public function autosubscribetemplateconfig()
  44. {
  45. D('Seller/User')->mange_subscribetemplate_auto();
  46. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  47. }
  48. public function autotemplateconfig()
  49. {
  50. global $_W;
  51. global $_GPC;
  52. D('Seller/User')->mange_template_auto();
  53. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  54. }
  55. public function templateconfig()
  56. {
  57. $_GPC = I('request.');
  58. if( !isset($_GPC['type']) || empty($_GPC['type']) )
  59. {
  60. $_GPC['type'] = 1;
  61. }
  62. if($_GPC['type']=='2'){
  63. //获取选中的会员id
  64. $data = array();
  65. $data['userids'] = $_GPC['limit_user_list'];
  66. //提交更新
  67. if(IS_POST)
  68. {
  69. $platform = array();
  70. $platform['platform_send_info_member']= $data['userids'];
  71. D('Seller/Config')->update($platform);
  72. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  73. }
  74. //查询下会员id
  75. $send = M('lionfish_comshop_config')->where( array('name' => 'platform_send_info_member') )->find();
  76. if(!empty($send['value'])){
  77. //in语句查询会员对应信息
  78. $list = array();
  79. if( !empty($send['value']) )
  80. {
  81. $list = M('lionfish_comshop_member')->field('member_id, username as nickname,avatar')->where('member_id in('.$send['value'].')')->select();
  82. }
  83. //组合
  84. foreach($list as $key => $vv){
  85. $userall =array(
  86. 'member_id' => $vv[member_id],
  87. 'nickname' => $vv[nickname],
  88. 'avatar' => tomedia($vv[avatar]),
  89. );
  90. $user_list[$key]=$userall;
  91. }
  92. }else{
  93. $user_list = array();
  94. }
  95. }
  96. else if( $_GPC['type']=='3' )
  97. {
  98. $member_group_list = M('lionfish_comshop_member_group')->order('id asc')->select();
  99. $this->member_group_list = $member_group_list;
  100. }
  101. else{
  102. if ( IS_POST ) {
  103. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  104. $data['wepro_share_title'] = trim($data['wepro_share_title']);
  105. D('Seller/Config')->update($data);
  106. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  107. }
  108. $data = D('Seller/Config')->get_all_config();
  109. }
  110. $type = I('get.type',1);
  111. $this->type = $type;
  112. $this->user_list = $user_list;
  113. $this->_GPC = $_GPC;
  114. $this->data = $data;
  115. $this->display();
  116. }
  117. public function templateconfig_set()
  118. {
  119. $_GPC = I('request.');
  120. if (IS_POST) {
  121. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  122. D('Seller/Config')->update($data);
  123. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  124. }
  125. $data = D('Seller/Config')->get_all_config();
  126. $this->data = $data;
  127. include $this->display();
  128. }
  129. public function templateconfig_fenxi()
  130. {
  131. $_GPC = I('request.');
  132. $subtitle = $_GPC['subtitle'];
  133. $datas = $_GPC['datas'];
  134. $all_msg_send_type = $_GPC['all_msg_send_type'];
  135. $member_id = $_GPC['member_id'];
  136. $member_group_id = $_GPC['member_group_id'];
  137. $all_send_template_id = $_GPC['all_send_template_id'];
  138. $link = $_GPC['link'];
  139. $limit_user_list = $_GPC['limit_user_list'];
  140. if( $all_msg_send_type == 1)
  141. {
  142. //单人
  143. if( empty($limit_user_list) )
  144. {
  145. show_json(0, '请选择会员');
  146. die();
  147. }
  148. }else if( $all_msg_send_type == 2 )
  149. {
  150. //用户组
  151. if( empty($member_group_id) || $member_group_id <= 0 )
  152. {
  153. show_json(0, '请选择会员组');
  154. die();
  155. }
  156. }else if( $all_msg_send_type == 3 )
  157. {
  158. //群发所有人
  159. }
  160. if( empty($datas) )
  161. {
  162. show_json(0, '请填写模板消息内容');
  163. die();
  164. }
  165. $template_data = array();
  166. foreach( $datas as $key => $val )
  167. {
  168. $str = $key;
  169. $str = str_replace('{{','', $str );
  170. $str = str_replace('.DATA','', $str );
  171. $tp_key = str_replace('}}','', $str );
  172. $template_data[$tp_key] = array('value' => ($val), 'color' => '#173177');
  173. }
  174. if( empty($all_send_template_id) )
  175. {
  176. show_json(0, '请填写模板ID');
  177. die();
  178. }
  179. if( empty($link) )
  180. {
  181. show_json(0, '请填写点击链接');
  182. die();
  183. }
  184. @set_time_limit(0);
  185. //todo///
  186. if( $all_msg_send_type == 3 )
  187. {
  188. $membercount = M('lionfish_comshop_member')->count();
  189. if( empty($membercount) || $membercount == 0 )
  190. {
  191. show_json(0, '暂无会员可发送消息');
  192. die();
  193. }
  194. $msg_order = array();
  195. $msg_order['uniacid'] = 0;
  196. $msg_order['template_data'] = serialize($template_data);
  197. $msg_order['url'] = $link;
  198. $msg_order['open_id'] = '';
  199. $msg_order['template_id'] = $all_send_template_id;
  200. $msg_order['type'] = 1;
  201. $msg_order['state'] = 0;
  202. $msg_order['total_count'] = $membercount;
  203. $msg_order['send_total_count'] = 0;
  204. $msg_order['addtime'] = time();
  205. M('lionfish_comshop_templatemsg')->add( $msg_order );
  206. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  207. }else{
  208. if( $all_msg_send_type == 1 )
  209. {
  210. $mb_info_all = M('lionfish_comshop_member')->field('we_openid')->where( 'member_id in ('.$limit_user_list.')' )->select();
  211. foreach($mb_info_all as $mb_info )
  212. {
  213. $msg_order = array();
  214. $msg_order['uniacid'] = 0;
  215. $msg_order['template_data'] = serialize($template_data);
  216. $msg_order['url'] = $link;
  217. $msg_order['open_id'] = $mb_info['we_openid'];
  218. $msg_order['template_id'] = $all_send_template_id;
  219. $msg_order['type'] = 0;
  220. $msg_order['state'] = 0;
  221. $msg_order['addtime'] = time();
  222. M('lionfish_comshop_templatemsg')->add( $msg_order );
  223. }
  224. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  225. }else if( $all_msg_send_type == 2 )
  226. {
  227. $mb_info_list = M('lionfish_comshop_member')->field('we_openid')->where( array('groupid' => $member_group_id ) )->select();
  228. foreach( $mb_info_list as $mb_info )
  229. {
  230. $msg_order = array();
  231. $msg_order['uniacid'] = 0;
  232. $msg_order['template_data'] = serialize($template_data);
  233. $msg_order['url'] = $link;
  234. $msg_order['open_id'] = $mb_info['we_openid'];
  235. $msg_order['template_id'] = $all_send_template_id;
  236. $msg_order['type'] = 0;
  237. $msg_order['state'] = 0;
  238. $msg_order['addtime'] = time();
  239. M('lionfish_comshop_templatemsg')->add($msg_order);
  240. }
  241. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  242. }
  243. }
  244. }
  245. public function subscribetemplateconfig()
  246. {
  247. $_GPC = I('request.');
  248. if ( IS_POST ) {
  249. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  250. $data['wepro_share_title'] = trim($data['wepro_share_title']);
  251. D('Seller/Config')->update($data);
  252. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  253. }
  254. $data = D('Seller/Config')->get_all_config();
  255. $this->data = $data;
  256. $this->display();
  257. }
  258. /**
  259. * tabbar设置
  260. */
  261. public function tabbar()
  262. {
  263. if ( IS_POST) {
  264. $gpc = I('request.');
  265. $data = ((is_array($gpc['parameter']) ? $gpc['parameter'] : array()));
  266. $param = array();
  267. $param['wepro_tabbar_list'] = array();
  268. $param['wepro_tabbar_list']['t1'] = trim($data['wepro_tabbar_text1']);
  269. $param['wepro_tabbar_list']['t2'] = trim($data['wepro_tabbar_text2']);
  270. $param['wepro_tabbar_list']['t3'] = trim($data['wepro_tabbar_text3']);
  271. $param['wepro_tabbar_list']['t4'] = trim($data['wepro_tabbar_text4']);
  272. $param['wepro_tabbar_list']['t5'] = trim($data['wepro_tabbar_text5']);
  273. $param['wepro_tabbar_list']['s1'] = save_media($data['wepro_tabbar_selectedIconPath1']);
  274. $param['wepro_tabbar_list']['s2'] = save_media($data['wepro_tabbar_selectedIconPath2']);
  275. $param['wepro_tabbar_list']['s3'] = save_media($data['wepro_tabbar_selectedIconPath3']);
  276. $param['wepro_tabbar_list']['s4'] = save_media($data['wepro_tabbar_selectedIconPath4']);
  277. $param['wepro_tabbar_list']['s5'] = save_media($data['wepro_tabbar_selectedIconPath5']);
  278. $param['wepro_tabbar_list']['i1'] = save_media($data['wepro_tabbar_iconPath1']);
  279. $param['wepro_tabbar_list']['i2'] = save_media($data['wepro_tabbar_iconPath2']);
  280. $param['wepro_tabbar_list']['i3'] = save_media($data['wepro_tabbar_iconPath3']);
  281. $param['wepro_tabbar_list']['i4'] = save_media($data['wepro_tabbar_iconPath4']);
  282. $param['wepro_tabbar_list']['i5'] = save_media($data['wepro_tabbar_iconPath5']);
  283. $param['wepro_tabbar_list'] = serialize($param['wepro_tabbar_list']);
  284. $param['open_tabbar_type'] = $data['open_tabbar_type'];
  285. $param['open_tabbar_out_weapp'] = $data['open_tabbar_out_weapp'];
  286. $param['tabbar_out_appid'] = $data['tabbar_out_appid'];
  287. $param['tabbar_out_link'] = $data['tabbar_out_link'];
  288. $param['tabbar_out_type'] = $data['tabbar_out_type'];
  289. $param['wepro_tabbar_selectedColor'] = $data['wepro_tabbar_selectedColor'];
  290. $param['wepro_tabbar_bgColor'] = $data['wepro_tabbar_bgColor'];
  291. D('Seller/Config')->update($param);
  292. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  293. }
  294. $data = D('Seller/Config')->get_all_config();
  295. if(!is_array($data['wepro_tabbar_list']))
  296. $data['wepro_tabbar_list'] = unserialize($data['wepro_tabbar_list'] );
  297. $this->data = $data;
  298. $this->display();
  299. }
  300. }
  301. ?>