WeprogramController.class.php 11 KB

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