WeprogramController.class.php 10.0 KB

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