MptradecompontsController.class.php 11 KB

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