MptradecompontsController.class.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Seller\Controller;
  10. class MptradecompontsController extends CommonController{
  11. protected $menu;
  12. protected function _initialize(){
  13. parent::_initialize();
  14. $menu = array(
  15. 'title' => '交易组件',
  16. 'subtitle' => '交易组件',
  17. 'route' => 'mptradecomponts/index',
  18. 'items' => array(
  19. array('title' => '商品列表', 'route' => 'mptradecomponts/index'),
  20. array('title' => '设置', 'route' => 'mptradecomponts/config'), )
  21. );
  22. $perm_url = strtolower(CONTROLLER_NAME) .'/'. strtolower(ACTION_NAME);
  23. $this->assign('perm_url', $perm_url );
  24. //组件权限方法===begin
  25. if(SELLERUID != 1)
  26. {
  27. $seller_info = M('seller')->field('s_role_id')->where( array('s_id' => SELLERUID ) )->find();
  28. $perm_role = M('lionfish_comshop_perm_role')->where( array('id' => $seller_info['s_role_id']) )->find();
  29. $perms_str = $perm_role['perms2'];
  30. $items = [];
  31. $can_use_routearr = [];
  32. foreach( $menu['items'] as $val )
  33. {
  34. $val_route = str_replace('/','.', $val['route']);
  35. if( strpos($perms_str, '.'.$val_route) !== false )
  36. {
  37. $items[] = $val;
  38. $can_use_routearr[] = strtolower($val['route']);
  39. }
  40. }
  41. $menu['items'] = $items;
  42. if( empty($can_use_routearr) )
  43. {
  44. $this->redirect( 'application/index', [], 1,'您没有当前应用权限' );
  45. }else if( !in_array($perm_url , $can_use_routearr ) )
  46. {
  47. $this->redirect( $can_use_routearr[0] );
  48. }
  49. }
  50. //组件方法end
  51. $this->menu = $menu;
  52. $this->assign('menu', $menu );
  53. }
  54. /**
  55. * @author yj
  56. * @desc 拉取已经提交给微信的商品
  57. * * 枚举-edit_status
  58. 枚举值 描述 商品草稿状态
  59. 0 初始值
  60. 1 编辑中
  61. 2 审核中
  62. 3 审核失败
  63. 4 审核成功
  64. * 枚举-status 商品线上状态
  65. 枚举值 描述
  66. 0 初始值
  67. 5 上架
  68. 11 自主下架
  69. 13 违规下架/风控系统下架
  70. */
  71. public function index()
  72. {
  73. $_GPC = I('request.');
  74. $this->gpc = $_GPC;
  75. $condition = ' 1 ';
  76. $pindex = max(1, intval($_GPC['page']));
  77. $psize = 20;
  78. $need_edit_spu = 0;
  79. if (!empty($_GPC['need_edit_spu'])) {
  80. $need_edit_spu = intval( $_GPC['need_edit_spu'] );
  81. }
  82. $result = D('Seller/MpModifyTradeComponts')->getTxGoodsList( $pindex , $psize , $need_edit_spu );
  83. $total = 0;
  84. $list = [];
  85. if( $result['errcode'] == 0 )
  86. {
  87. $total = $result['total_num'];
  88. $list = $result['spus'];
  89. if( !empty($list) )
  90. {
  91. foreach( $list as $key => $val )
  92. {
  93. if( empty($val['title']) )
  94. {
  95. $val['title'] = '腾讯审核中,商品图片和标题审核成功后显示 ';
  96. }else{
  97. $val['title'] = $this->decodeUnicode ($val['title']);
  98. }
  99. switch( $val['status'] )
  100. {
  101. case 0:
  102. $val['status_name'] = '初始值';
  103. break;
  104. case 5:
  105. $val['status_name'] = '上架';
  106. break;
  107. case 11:
  108. $val['status_name'] = '自主下架';
  109. break;
  110. case 13:
  111. $val['status_name'] = '违规下架/风控系统下架';
  112. break;
  113. }
  114. switch( $val['edit_status'] )
  115. {
  116. case 0:
  117. $val['edit_status_name'] = '初始值';
  118. break;
  119. case 1:
  120. $val['edit_status_name'] = '编辑中';
  121. break;
  122. case 2:
  123. $val['edit_status_name'] = '审核中';
  124. break;
  125. case 3:
  126. $val['edit_status_name'] = '审核失败:'.$val['audit_info']['reject_reason'];
  127. break;
  128. case 4:
  129. $val['edit_status_name'] = '审核成功';
  130. break;
  131. }
  132. $list[$key] = $val;
  133. }
  134. }
  135. }
  136. $pager = pagination2($total, $pindex, $psize);
  137. $this->list = $list;
  138. $this->pager = $pager;
  139. $this->display();
  140. }
  141. //把unicode转化成中文
  142. private function decodeUnicode($str)
  143. {
  144. return preg_replace_callback('/\\\\u([0-9a-f]{4})/i',
  145. create_function(
  146. '$matches',
  147. 'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");'
  148. ),
  149. $str);
  150. }
  151. /**
  152. * @author yj
  153. * @desc 撤销审核
  154. */
  155. public function del_audit()
  156. {
  157. $out_product_id = I('get.out_product_id');
  158. $result = D('Seller/MpModifyTradeComponts')->delAudit( $out_product_id );
  159. if( $result['errcode'] == 0 )
  160. {
  161. show_json(1, array('url' => $_SERVER['HTTP_REFERER']) );
  162. die();
  163. }else{
  164. show_json(0, array('message' => $result['errmsg']) );
  165. die();
  166. }
  167. }
  168. /**
  169. * @author yj
  170. * @desc 删除商品
  171. */
  172. public function del()
  173. {
  174. $out_product_id = I('get.out_product_id');
  175. $result = D('Seller/MpModifyTradeComponts')->del( $out_product_id );
  176. if( $result['errcode'] == 0 )
  177. {
  178. show_json(1, array('url' => $_SERVER['HTTP_REFERER']) );
  179. die();
  180. }else{
  181. show_json(0, array('message' => $result['errmsg']) );
  182. die();
  183. }
  184. }
  185. /**
  186. * @author yj
  187. * @desc 上架商品
  188. */
  189. public function listing()
  190. {
  191. $out_product_id = I('get.out_product_id');
  192. $result = D('Seller/MpModifyTradeComponts')->listing( $out_product_id );
  193. if( $result['errcode'] == 0 )
  194. {
  195. show_json(1, array('url' => $_SERVER['HTTP_REFERER']) );
  196. die();
  197. }else{
  198. show_json(0, array('message' => $result['errmsg']) );
  199. die();
  200. }
  201. }
  202. public function delisting()
  203. {
  204. $out_product_id = I('get.out_product_id');
  205. $result = D('Seller/MpModifyTradeComponts')->delisting( $out_product_id );
  206. if( $result['errcode'] == 0 )
  207. {
  208. show_json(1, array('url' => $_SERVER['HTTP_REFERER']) );
  209. die();
  210. }else{
  211. show_json(0, array('message' => $result['errmsg']) );
  212. die();
  213. }
  214. }
  215. /**
  216. * @author yj
  217. * @desc 添加商品
  218. */
  219. public function addGoods()
  220. {
  221. if (IS_POST) {
  222. $result = D('Seller/MpModifyTradeComponts')->addGoods();
  223. if( $result['code'] == 0 )
  224. {
  225. show_json(1, array('url' => U('mptradecomponts/index')) );
  226. die();
  227. }else if( $result['code'] == 1 ){
  228. show_json(0, array('message' => $result['message']) );
  229. die();
  230. }
  231. }
  232. //获取类目数据
  233. $catelist = D('Seller/MpModifyTradeComponts')->shopCatList();
  234. $last_third_cate_id = 0;
  235. $this->assign('last_third_cate_id', $last_third_cate_id);
  236. $this->assign('catelist', $catelist['data'] );
  237. $this->display('Mptradecomponts/addGoods');
  238. }
  239. public function update()
  240. {
  241. if (IS_POST) {
  242. $result = D('Seller/MpModifyTradeComponts')->addGoods();
  243. if( $result['code'] == 0 )
  244. {
  245. show_json(1, array('url' => $_SERVER['HTTP_REFERER']) );
  246. die();
  247. }else if( $result['code'] == 1 ){
  248. show_json(0, array('message' => $result['message']) );
  249. die();
  250. }
  251. }
  252. $goods_id = I('get.goods_id');
  253. $goods_info = M('lionfish_comshop_goods')->field('goodsname')->where(['id' => $goods_id ])->find();
  254. //获取类目数据
  255. $catelist = D('Seller/MpModifyTradeComponts')->shopCatList();
  256. $last_third_cate_id = 0;
  257. $this->assign('last_third_cate_id', $last_third_cate_id);
  258. $this->assign('catelist', $catelist['data'] );
  259. $this->assign('goods_info', $goods_info );
  260. $this->assign('goods_id', $goods_id );
  261. $this->display();
  262. }
  263. public function config()
  264. {
  265. $_GPC = I('request.');
  266. if (IS_POST) {
  267. //提交前,获取一次是否接入请求,接入不允许使用了
  268. $check_result = D('Seller/MpModifyTradeComponts')->registerCheck();
  269. if( $check_result['errcode'] == '1040003' )
  270. {
  271. show_json(0, array('message' => '该小程序还没接入,请前往微信小程序后台接入交易组件' ) );
  272. die();
  273. }
  274. if( $check_result['errcode'] == 0 && $check_result['data']['status'] == 3 )
  275. {
  276. show_json(0, array('message' => '小程序封禁中' ) );
  277. die();
  278. }
  279. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  280. $data['isopen_tradecomponts'] = isset($data['isopen_tradecomponts']) ? $data['isopen_tradecomponts']:0;
  281. $data['tradecomponts_token'] = isset($data['tradecomponts_token']) ? $data['tradecomponts_token']:'';
  282. $data['tradecomponts_encodeingaeskey'] = isset($data['tradecomponts_encodeingaeskey']) ? $data['tradecomponts_encodeingaeskey']:'';
  283. D('Seller/Config')->update($data);
  284. show_json(1, array('url' => $_SERVER['HTTP_REFERER']) );
  285. die();
  286. }
  287. $data = D('Seller/Config')->get_all_config();
  288. $this->data = $data;
  289. $this->display();
  290. }
  291. }
  292. ?>