MpModifyTradeCompontsModel.class.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. <?php
  2. /**
  3. * lionfish 狮子鱼社区团购系统
  4. *
  5. *
  6. * @author fish
  7. * @desc 微信小程序自定义版交易组件及开放接口
  8. *
  9. */
  10. namespace Seller\Model;
  11. class MpModifyTradeCompontsModel extends UserModel {
  12. /**
  13. * @author yj
  14. * @demo array(2) { ["errcode"]=> int(1040002) ["errmsg"]=> string(56) "该小程序已经接入 rid: 6078dde8-7955f8e0-309fe346" } errcode=0
  15. * @desc 接入申请
  16. */
  17. public function apply()
  18. {
  19. $access_token = $this->getMpAccessToken();
  20. $url = "https://api.weixin.qq.com/shop/register/apply?access_token={$access_token}";
  21. $result_json = $this->sendhttps_post( $url , json_encode([]) );
  22. $result = json_decode( $result_json, true );
  23. return $result;
  24. }
  25. /**
  26. * @author yj
  27. * @demo array(2) { ["errcode"]=> int(0) ["data"]=> array(3) { ["status"]=> int(2) ["reject_reason"]=> string(0) "" ["access_info"]=> array(2) { ["spu_audit_success"]=> int(0) ["pay_order_success"]=> int(0) } } }
  28. * @desc 如果账户未接入,将返回错误码1040003 查询接入结果
  29. * @return mixed
  30. */
  31. public function registerCheck()
  32. {
  33. $access_token = $this->getMpAccessToken();
  34. $url = "https://api.weixin.qq.com/shop/register/check?access_token={$access_token}";
  35. $result_json = $this->sendhttps_post( $url , json_encode([]) );
  36. $result = json_decode( $result_json, true );
  37. return $result;
  38. }
  39. /**
  40. * @author yj
  41. * @desc 获取运营类目
  42. * @demo
  43. * {
  44. "errcode": 0,
  45. "errmsg":"ok",
  46. "third_cat_list":
  47. [
  48. {
  49. "third_cat_id": 6493,
  50. "third_cat_name": "爬行垫/毯",
  51. "qualification": "",
  52. "qualification_type": 0,
  53. "product_qualification": "《国家强制性产品认证证书》(CCC安全认证证书)",
  54. "product_qualification_type": 1,
  55. "first_cat_id": 6472,
  56. "first_cat_name": "玩具乐器",
  57. "second_cat_id": 6489,
  58. "second_cat_name": "健身玩具"
  59. },
  60. ...
  61. ]
  62. }
  63. 请求
  64. */
  65. public function shopCatList()
  66. {
  67. $wepro_appid = D('Home/Front')->get_config_by_name('wepro_appid');
  68. $key = "{$wepro_appid}mpweixin_shop_list";
  69. $data = json_decode( S($key) , true);
  70. if ( empty( $data ) || $data['expire_time'] < time() )
  71. {
  72. //重新获取
  73. $access_token = $this->getMpAccessToken();
  74. $url = "https://api.weixin.qq.com/shop/cat/get?access_token={$access_token}";
  75. $result_json = $this->sendhttps_post( $url , json_encode([]) );
  76. $result = json_decode( $result_json, true );
  77. if( $result['errcode'] == 0 )
  78. {
  79. $third_cat_list = $result['third_cat_list'];
  80. $need_data = [];
  81. $need_data['expire_time'] = time() + 86400;
  82. $need_data['third_cat_list'] = $third_cat_list;
  83. S( $key ,json_encode($need_data));
  84. return ['code' => 0, 'data' => $third_cat_list ];
  85. }else{
  86. return ['code' => 1, 'message' => $result['errmsg'].':'.$result['errcode'] ];
  87. }
  88. }
  89. else{
  90. return ['code' => 0, 'data' => $data['third_cat_list']];
  91. }
  92. }
  93. /**
  94. * @author yj
  95. * @desc 添加商品到腾讯接口
  96. * @return array
  97. */
  98. public function addGoods()
  99. {
  100. M()->startTrans();
  101. $goods_id = I('post.goods_id', 0);
  102. $tx_cate_id = I('post.tx_cate_id', 0);
  103. $thumbs = I('post.thumbs', [] );
  104. $is_need_qualification = I('post.is_need_qualification', 0);
  105. if( $goods_id <= 0 )
  106. {
  107. M()->rollback();
  108. return ['code' => 1, 'message' => '请选择商品'];
  109. }
  110. if( $tx_cate_id == 0 )
  111. {
  112. M()->rollback();
  113. return ['code' => 1, 'message' => '请选择分类'];
  114. }
  115. if( $is_need_qualification == 1 )
  116. {
  117. if( empty($thumbs) )
  118. {
  119. M()->rollback();
  120. return ['code' => 1, 'message' => '需要上传资料,请上传后提交'];
  121. }
  122. }
  123. //判断商品状态是否正常,需要提交去审核的
  124. $goods_info = M('lionfish_comshop_goods')->where(['id' => $goods_id ])->find();
  125. if( $goods_info['grounding'] != 1 )
  126. {
  127. M()->rollback();
  128. return ['code' => 1, 'message' => '商品必须是已上架状态'];
  129. }
  130. $goods_option = M('lionfish_comshop_goods_option')->where(['goods_id' => $goods_id ])->find();
  131. if( empty($goods_option) )
  132. {
  133. //M()->rollback();
  134. // return ['code' => 1, 'message' => '腾讯要求商品必须有规格,您可以仅设置1个规格'];
  135. }
  136. //0、入库商品的申请资料
  137. //判断是否存在
  138. $tradecomponts_info = M('lionfish_comshop_goods_tradecomponts')->where(['goods_id' => $goods_id ])->find();
  139. $ins_data = [];
  140. $ins_data['goods_id'] = $goods_id;
  141. $ins_data['state'] = 0;
  142. $ins_data['qualification_imagelist'] = serialize( $thumbs );
  143. $ins_data['third_cate_id'] = $tx_cate_id;
  144. $ins_data['addtime'] = time();
  145. if( empty($tradecomponts_info) )
  146. {
  147. $tradecomponts_id = M('lionfish_comshop_goods_tradecomponts')->add( $ins_data );
  148. // //1、开始构造商品数据结构 2、提交给腾讯审核
  149. $result = $this->sendTradeGoodsToApply( $tradecomponts_id , 0 );
  150. }else{
  151. unset( $ins_data['addtime'] );
  152. M('lionfish_comshop_goods_tradecomponts')->where( ['id' => $tradecomponts_info['id']] )->save( $ins_data );
  153. $tradecomponts_id = $tradecomponts_info['id'];
  154. // //1、开始构造商品数据结构 2、提交给腾讯审核
  155. $result = $this->sendTradeGoodsToApply( $tradecomponts_id , 1 );
  156. }
  157. //3、判断审核状态
  158. //提交给腾讯审核时报错。
  159. if( $result['errcode'] != 0 )
  160. {
  161. M()->rollback();
  162. return ['code' => 1, 'message' => $result['errmsg'].',errcode'.$result['errcode'] ];
  163. }
  164. $tx_product_id = $result['data']['product_id'];
  165. M('lionfish_comshop_goods_tradecomponts')->where( ['goods_id' =>$goods_id ] )->save( ['tx_product_id' => $tx_product_id ] );
  166. M()->commit();
  167. return ['code' => 0];
  168. }
  169. /**
  170. * @author yj
  171. * @desc 发送审核给腾讯
  172. * @param $tradecomponts_id
  173. * @return mixed
  174. */
  175. public function sendTradeGoodsToApply( $tradecomponts_id , $is_update = 0)
  176. {
  177. $trade_info = M('lionfish_comshop_goods_tradecomponts')->where( ['id' => $tradecomponts_id ] )->find();
  178. if( empty($trade_info) )
  179. {
  180. return ['code' =>1, 'message' => '没有找到交易组件商品'];
  181. }
  182. $goods_option = M('lionfish_comshop_goods_option')->where(['goods_id' => $trade_info['goods_id'] ])->find();
  183. if( empty($goods_option) )
  184. {
  185. //return ['code' => 1, 'message' => '腾讯要求商品必须有规格,您的商品不符合审核要求'];
  186. }
  187. $goods_info = M('lionfish_comshop_goods')->where(['id' => $trade_info['goods_id'] ])->find();
  188. $goods_common_info = M('lionfish_comshop_good_common')->where(['goods_id' => $trade_info['goods_id'] ])->find();
  189. $piclist_arr = M('lionfish_comshop_goods_images')->where( array('goods_id' => $trade_info['goods_id'] ) )->order('id asc')->select();
  190. $piclist = [];
  191. foreach($piclist_arr as $val)
  192. {
  193. $piclist[] = tomedia($val['image']);
  194. }
  195. if( empty($goods_common_info['big_img']) )
  196. {
  197. $big_img = $piclist[0];
  198. }else{
  199. $big_img = tomedia($goods_common_info['big_img']);
  200. }
  201. $qualification_imagelist = unserialize( $trade_info['qualification_imagelist']);
  202. if( !empty($qualification_imagelist) )
  203. {
  204. foreach( $qualification_imagelist as $key => $val )
  205. {
  206. $qualification_imagelist[$key] = tomedia( $val );
  207. }
  208. }
  209. //开始构造资料
  210. $data = [];
  211. $data['out_product_id'] = $trade_info['goods_id'];
  212. $data['title'] = $goods_info['goodsname'];
  213. $data['path'] = "lionfish_comshop/pages/goods/goodsDetail?id=".$trade_info['goods_id'];
  214. $data['head_img'] = $piclist;
  215. if( !empty($qualification_imagelist) )
  216. {
  217. $data['qualification_pics'] = $qualification_imagelist;
  218. }
  219. $data['third_cat_id'] = $trade_info['third_cate_id'];
  220. $data['brand_id'] = '2100000000';
  221. $goods_option_item_value = M('lionfish_comshop_goods_option_item_value')->where(['goods_id' => $trade_info['goods_id'] ])->order('id asc')->select();
  222. $sku_list = [];
  223. if( !empty($goods_option_item_value) )
  224. {
  225. foreach($goods_option_item_value as $value )
  226. {
  227. $option_item_ids = $value['option_item_ids'];
  228. $productprice = $value['productprice'];
  229. $marketprice = $value['marketprice'];
  230. $stock = $value['stock'];
  231. $option_item_ids_arr = explode('_', $option_item_ids );
  232. $sku_attr = [];
  233. $image = '';
  234. foreach( $option_item_ids_arr as $option_item_id )
  235. {
  236. $option_item_value = M('lionfish_comshop_goods_option_item')->where(['id' => $option_item_id ])->find();
  237. $title = $option_item_value['title'];
  238. $goods_option_id = $option_item_value['goods_option_id'];
  239. $thumb = empty($option_item_value['thumb']) ? '' : tomedia( $option_item_value['thumb'] );
  240. if( !empty($thumb) )
  241. {
  242. $image = $thumb;
  243. }
  244. $goods_option_value = M('lionfish_comshop_goods_option')->where(['id' => $goods_option_id])->find();
  245. $option_title = $goods_option_value['title'];
  246. $sku_attr['attr_key'] = '请选择'.$option_title;
  247. $sku_attr['attr_value'] = $title;
  248. }
  249. $sku = [];
  250. $sku['out_product_id'] = $trade_info['goods_id'];
  251. $sku['out_sku_id'] = $value['id'];
  252. $sku['thumb_img'] = empty($image) ? $big_img : $image;
  253. $sku['sale_price'] = round($productprice, 2 );
  254. $sku['market_price'] = round($marketprice, 2 );
  255. $sku['stock_num'] = $stock;
  256. $sku['skus'] = $sku_attr;
  257. $sku_list[] = $sku;
  258. }
  259. }else{
  260. $sku = [];
  261. $sku['out_product_id'] = $trade_info['goods_id'];
  262. $sku['out_sku_id'] = $trade_info['goods_id'];
  263. $sku['thumb_img'] = empty($image) ? $big_img : $image;
  264. $sku['sale_price'] = round($goods_info['price'], 2 );
  265. $sku['market_price'] = round($goods_info['productprice'], 2 );
  266. $sku['stock_num'] = $goods_info['total'];
  267. $sku_attr = [];
  268. $sku_attr[0]['attr_key'] = '请选择商品';
  269. $sku_attr[0]['attr_value'] = empty($goods_info['subtitle']) ? $goods_info['goodsname'] : $goods_info['subtitle'];
  270. $sku['skus'] = $sku_attr;
  271. $sku_list[] = $sku;
  272. }
  273. $data['skus'] = $sku_list;
  274. $access_token = $this->getMpAccessToken();
  275. if($is_update == 1)
  276. {
  277. $url = "https://api.weixin.qq.com/shop/spu/update?access_token={$access_token}";
  278. }else{
  279. $url = "https://api.weixin.qq.com/shop/spu/add?access_token={$access_token}";
  280. }
  281. $result_json = $this->sendhttps_post( $url , json_encode( $data ) );
  282. $result = json_decode( $result_json, true );
  283. return $result;
  284. }
  285. /**
  286. * @author yj
  287. * @desc 上传图片获取mediaid
  288. * @param $file_path
  289. * @demo array(2) { ["code"]=> int(0) ["media_id"]=> string(96) "wxashop_OwtQWWaTP5KqZ0Y6RECb5bcWKg2hI9W7E/vTIAPaNAvqxnibXr3xcD/KEowcvTzbSEDkD3Q6lvhTB6437AHymw==" }
  290. * @return mixed
  291. */
  292. public function uploadImg( $file_path )
  293. {
  294. $access_token = $this->getMpAccessToken();
  295. $url = "https://api.weixin.qq.com/shop/img/upload?access_token={$access_token}";
  296. $data = [];
  297. $data['media'] = '@'.$file_path;
  298. $cfile = new \CURLFile($file_path );
  299. $imgdata = array('media' => $cfile);
  300. $result_json = $this->sendhttps_post( $url , $imgdata );
  301. $result = json_decode( $result_json, true );
  302. if( $result['errcode'] == 0 )
  303. {
  304. return ['code' => 0, 'media_id' => $result['img_info']['media_id'] ];
  305. }else{
  306. return ['code' => 1, 'message' => $result['errmsg'].':errcode='.$result['errmsg'] ];
  307. }
  308. }
  309. /**
  310. * @author yj
  311. * @desc 上传品牌信息
  312. * @param $license 营业执照或组织机构代码证,图片url/media_id
  313. * @param $brand_audit_type 认证审核类型 RegisterType
  314. * @param $trademark_type 商标分类 TrademarkType
  315. * @param $brand_management_type 选择品牌经营类型 BrandManagementType
  316. * @param $commodity_origin_type 商品产地是否进口 CommodityOriginType
  317. * @param $brand_wording 商标/品牌词
  318. * @param $sale_authorization 销售授权书(如商持人为自然人,还需提供有其签名的身份证正反面扫描件),图片url/media_id
  319. * @param $trademark_registration_certificate 商标注册证书,图片url/media_id
  320. * @param $trademark_change_certificate 商标变更证明,图片url/media_id
  321. * @param $trademark_registrant 商标注册人姓名
  322. * @param $trademark_registrant_nu 商标注册号/申请号
  323. * @param $trademark_authorization_period 商标有效期,yyyy-MM-dd HH:mm:ss
  324. * @param $trademark_registration_application 商标注册申请受理通知书,图片url/media_id
  325. * @param $trademark_applicant 商标申请人姓名
  326. * @param $trademark_application_time 商标申请时间, yyyy-MM-dd HH:mm:ss
  327. * @param string $imported_goods_form 中华人民共和国海关进口货物报关单,图片url/media_id
  328. * @说明:
  329. * 枚举-WxaAuditSourceType
  330. 1 注册
  331. 2 改名
  332. 3 新增品牌
  333. 4 新增类目
  334. 5 新增品牌类目
  335. 6 新增商品
  336. 7 支付审核
  337. *枚举-RegisterType
  338. * 1 国内品牌申请-R标
  339. 2 国内品牌申请-TM标
  340. 3 海外品牌申请-R标
  341. 4 海外品牌申请-TM标
  342. * 枚举-TrademarkType
  343. "1" 第1类
  344. "2" 第2类
  345. "3" 第3类
  346. ... ...
  347. "45" 第45类
  348. *
  349. * 枚举-BrandRegistrationType
  350. 枚举值 描述
  351. 1 R标
  352. 2 TM标
  353. 枚举-enum BrandManagementType
  354. 枚举值 描述
  355. 1 自有品牌
  356. 2 代理品牌
  357. 3 无品牌
  358. 枚举-CommodityOriginType
  359. 枚举值 描述
  360. 1 是
  361. 2 否
  362. */
  363. public function auditBrand( $license ,$brand_audit_type , $trademark_type , $brand_management_type , $commodity_origin_type , $brand_wording, $sale_authorization,
  364. $trademark_registration_certificate, $trademark_change_certificate ,
  365. $trademark_registrant, $trademark_registrant_nu , $trademark_authorization_period, $trademark_registration_application ,
  366. $trademark_applicant, $trademark_application_time , $imported_goods_form = '')
  367. {
  368. $access_token = $this->getMpAccessToken();
  369. $url = "https://api.weixin.qq.com/shop/audit/audit_brand?access_token={$access_token}";
  370. $data = [];
  371. $data['audit_req'] = [];
  372. $data['audit_req']['audit_req'] = $license;
  373. $data['audit_req']['brand_info'] = [];
  374. $data['audit_req']['brand_info']['brand_audit_type'] = $brand_audit_type;
  375. $data['audit_req']['brand_info']['trademark_type'] = $trademark_type;
  376. $data['audit_req']['brand_info']['brand_management_type'] = $brand_management_type;
  377. $data['audit_req']['brand_info']['commodity_origin_type'] = $commodity_origin_type;
  378. $data['audit_req']['brand_info']['brand_wording'] = $brand_wording;
  379. $data['audit_req']['brand_info']['sale_authorization'] = $sale_authorization;
  380. $data['audit_req']['brand_info']['trademark_registration_certificate'] = $trademark_registration_certificate;
  381. $data['audit_req']['brand_info']['trademark_change_certificate'] = $trademark_change_certificate;
  382. $data['audit_req']['brand_info']['trademark_registrant'] = $trademark_registrant;
  383. $data['audit_req']['brand_info']['trademark_registrant_nu'] = $trademark_registrant_nu;
  384. $data['audit_req']['brand_info']['trademark_authorization_period'] = $trademark_authorization_period;
  385. $data['audit_req']['brand_info']['trademark_registration_application'] = $trademark_registration_application;
  386. $data['audit_req']['brand_info']['trademark_applicant'] = $trademark_applicant;
  387. $data['audit_req']['brand_info']['trademark_application_time'] = $trademark_application_time;
  388. $data['audit_req']['brand_info']['imported_goods_form'] = $imported_goods_form;
  389. $result_json = $this->sendhttps_post( $url , json_encode( $data ) );
  390. $result = json_decode( $result_json, true );
  391. return $result;
  392. }
  393. /**
  394. * @author yj
  395. * @desc 类目审核
  396. * @param $license 营业执照或组织机构代码证,图片url
  397. * @param $level1 一级类目
  398. * @param $level2 二级类目
  399. * @param $level3 三级类目
  400. * @param $certificate 资质材料,图片url
  401. * @return mixed
  402. */
  403. public function auditCategory($license , $level1 , $level2 , $level3 , $certificate )
  404. {
  405. $access_token = $this->getMpAccessToken();
  406. $url = "https://api.weixin.qq.com/shop/audit/audit_category?access_token={$access_token}";
  407. $data = [];
  408. $data['audit_req'] = [];
  409. $data['audit_req']['license'] = $license;
  410. $data['audit_req']['category_info'] = [];
  411. $data['audit_req']['category_info']['level1'] = $level1;
  412. $data['audit_req']['category_info']['level2'] = $level2;
  413. $data['audit_req']['category_info']['level3'] = $level3;
  414. $data['audit_req']['category_info']['certificate'] = $certificate;
  415. $result_json = $this->sendhttps_post( $url , json_encode( $data ) );
  416. $result = json_decode( $result_json, true );
  417. return $result;
  418. }
  419. /**
  420. * @author yj
  421. * @desc 获取小程序资质 该接口返回的是曾经在小程序方提交过的审核,非组件的入驻审核! 如果曾经没有提交,没有储存历史文件,或是获取失败,接口会返回1050006
  422. * @return mixed
  423. */
  424. public function getMiniappCertificate()
  425. {
  426. $access_token = $this->getMpAccessToken();
  427. $url = "https://api.weixin.qq.com/shop/audit/get_miniapp_certificate?access_token={$access_token}";
  428. $data = [];
  429. $data['req_type'] = 2;
  430. $result_json = $this->sendhttps_post( $url , json_encode( $data ) );
  431. $result = json_decode( $result_json, true );
  432. return $result;
  433. }
  434. /**
  435. * @author yj
  436. * @desc 获取小程序accesstoken
  437. * @return mixed
  438. */
  439. public function getMpAccessToken()
  440. {
  441. $weixin_config = array();
  442. $weixin_config['appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  443. $weixin_config['appscert'] = D('Home/Front')->get_config_by_name('wepro_appsecret');
  444. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'], $weixin_config['appscert']);
  445. $re_access_token = $jssdk->getweAccessToken();
  446. return $re_access_token;
  447. }
  448. /**
  449. * @author yj
  450. * @desc 获取提交给腾讯的商品列表
  451. * @param int $page
  452. * @param int $perpage
  453. * @param int $need_edit_spu 默认0:获取线上数据, 1:获取草稿数据
  454. *
  455. * 枚举-edit_status
  456. 枚举值 描述
  457. 0 初始值
  458. 1 编辑中
  459. 2 审核中
  460. 3 审核失败
  461. 4 审核成功
  462. * 枚举-status
  463. 枚举值 描述
  464. 0 初始值
  465. 5 上架
  466. 11 自主下架
  467. 13 违规下架/风控系统下架
  468. * @return mixed
  469. */
  470. public function getTxGoodsList( $page =1 , $perpage = 20 , $need_edit_spu = 0)
  471. {
  472. $access_token = $this->getMpAccessToken();
  473. $url = "https://api.weixin.qq.com/shop/spu/get_list?access_token={$access_token}";
  474. $data = [];
  475. $data['page'] = $page;
  476. $data['page_size'] = $perpage;
  477. $data['need_edit_spu'] = $need_edit_spu;
  478. $result_json = $this->sendhttps_post( $url , json_encode( $data ) );
  479. $result = json_decode( $result_json, true );
  480. return $result;
  481. }
  482. /**
  483. * @author yj
  484. * @desc 撤销审核
  485. * @param $out_product_id
  486. * @return mixed
  487. */
  488. public function delAudit( $out_product_id )
  489. {
  490. $access_token = $this->getMpAccessToken();
  491. $url = "https://api.weixin.qq.com/shop/spu/del_audit?access_token={$access_token}";
  492. $data = [];
  493. $data['out_product_id'] = $out_product_id;
  494. $result_json = $this->sendhttps_post( $url , json_encode( $data ) );
  495. $result = json_decode( $result_json, true );
  496. return $result;
  497. }
  498. /**
  499. * @author yj
  500. * @desc 上架商品--自助下架的才能上架
  501. * @param $out_product_id
  502. * @return mixed
  503. */
  504. public function listing( $out_product_id )
  505. {
  506. $access_token = $this->getMpAccessToken();
  507. $url = "https://api.weixin.qq.com/shop/spu/listing?access_token={$access_token}";
  508. $data = [];
  509. $data['out_product_id'] = $out_product_id;
  510. $result_json = $this->sendhttps_post( $url , json_encode( $data ) );
  511. $result = json_decode( $result_json, true );
  512. return $result;
  513. }
  514. public function delisting( $out_product_id )
  515. {
  516. $access_token = $this->getMpAccessToken();
  517. $url = "https://api.weixin.qq.com/shop/spu/delisting?access_token={$access_token}";
  518. $data = [];
  519. $data['out_product_id'] = $out_product_id;
  520. $result_json = $this->sendhttps_post( $url , json_encode( $data ) );
  521. $result = json_decode( $result_json, true );
  522. return $result;
  523. }
  524. /**
  525. * @author yj
  526. * @desc 删除商品
  527. * @param $out_product_id
  528. * @return mixed
  529. */
  530. public function del( $out_product_id )
  531. {
  532. $access_token = $this->getMpAccessToken();
  533. $url = "https://api.weixin.qq.com/shop/spu/del?access_token={$access_token}";
  534. $data = [];
  535. $data['out_product_id'] = $out_product_id;
  536. $result_json = $this->sendhttps_post( $url , json_encode( $data ) );
  537. $result = json_decode( $result_json, true );
  538. if( $result['errcode'] == 0 )
  539. {
  540. M('lionfish_comshop_goods_tradecomponts')->where(['goods_id' => $out_product_id ])->delete();
  541. }
  542. return $result;
  543. }
  544. /**
  545. * @author yj
  546. * @desc 检验场景是否需要校验支付
  547. * @param string $scene
  548. * 参数 类型 说明
  549. errcode number 错误码
  550. errmsg string 错误信息
  551. is_matched number 0: 不在支付校验范围内,1: 在支付校验范围内
  552. * @return mixed
  553. */
  554. public function sceneCheck( $scene = '1175' )
  555. {
  556. $access_token = $this->getMpAccessToken();
  557. $url = "https://api.weixin.qq.com/shop/scene/check?access_token={$access_token}";
  558. $data = [];
  559. $data['scene'] = $scene;
  560. $result_json = $this->sendhttps_post( $url , json_encode( $data ) );
  561. $result = json_decode( $result_json, true );
  562. if( $result['errcode'] == 0 && $result['is_matched'] == 1 )
  563. {
  564. return 1;
  565. }else{
  566. return 0;
  567. }
  568. }
  569. /**
  570. * @author yj
  571. * @desc 获取交易订单信息
  572. * https://developers.weixin.qq.com/miniprogram/dev/framework/ministore/minishopopencomponent2/API/order/requestOrderPayment.html
  573. * @param $order_id
  574. */
  575. public function getTradeOrderInfo( $order_id , $time , $pay_total )
  576. {
  577. /**
  578. {
  579. "create_time": "2020-03-25 13:05:25",
  580. "type": 0, // 非必填,默认为0。0:普通场景, 1:合单支付
  581. "out_order_id": "xxxxx", // 必填,普通场景下的外部订单ID;合单支付(多订单合并支付一次)场景下是主外部订单ID
  582. "openid": "oTVP50O53a7jgmawAmxKukNlq3XI",
  583. "path": "/pages/order.html?out_order_id=xxxxx", // 这里的path中的最好有一个参数的值能和out_order_id的值匹配上
  584. "out_user_id": "323232323",
  585. "order_detail":
  586. {
  587. "product_infos":
  588. [
  589. {
  590. "out_product_id": "12345",
  591. "out_sku_id":"23456",
  592. "product_cnt": 10,
  593. "sale_price": 100, //生成这次订单时商品的售卖价,可以跟上传商品接口的价格不一致
  594. "path": "pages/productDetail/productDetail?productId=2176180",
  595. "title" : "洗洁精",
  596. "head_img": "http://img10.360buyimg.com/n1/s450x450_jfs/t1/85865/39/13611/488083/5e590a40E4bdf69c0/55c9bf645ea2b727.jpg",
  597. },
  598. ...
  599. ],
  600. "pay_info": {
  601. "pay_method": "微信支付",
  602. "prepay_id": "42526234625",
  603. "prepay_time": "2020-03-25 14:04:25"
  604. },
  605. "price_info": {
  606. "order_price": 1600,
  607. "freight": 500,
  608. "discounted_price": 100,
  609. "additional_price": 200,
  610. "additional_remarks": "税费"
  611. }
  612. },
  613. "delivery_detail": {
  614. "delivery_type": 1, // 1: 正常快递, 2: 无需快递, 3: 线下配送, 4: 用户自提
  615. },
  616. "address_info": {
  617. "receiver_name": "张三",
  618. "detailed_address": "详细收货地址信息",
  619. "tel_number": "收货人手机号码",
  620. "country": "国家,选填",
  621. "province": "省份,选填",
  622. "city": "城市,选填",
  623. "town": "乡镇,选填"
  624. }
  625. }
  626. */
  627. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  628. $member_info = M('lionfish_comshop_member')->where(['member_id' => $order_info['member_id'] ])->find();
  629. //we_openid
  630. $need_data = [];
  631. $need_data['create_time'] = date('Y-m-d H:i:s', $order_info['date_added'] );
  632. $need_data['out_order_id'] = $order_id;
  633. $need_data['openid'] = $member_info['we_openid'];
  634. $need_data['path'] = 'lionfish_comshop/pages/order/order?id='.$order_id;
  635. //订单详情todo...
  636. $order_detail = [];
  637. $order_goods_list = M('lionfish_comshop_order_goods')->where(['order_id' => $order_id ])->select();
  638. foreach($order_goods_list as $order_goods )
  639. {
  640. $product_infos = [];
  641. $product_infos['out_product_id'] = $order_goods['goods_id'];
  642. $product_infos['out_sku_id'] = "";
  643. $product_infos['product_cnt'] = $order_goods['quantity'];
  644. $product_infos['sale_price'] = $order_goods['price'] * 100;
  645. $product_infos['path'] = "lionfish_comshop/pages/goods/goodsDetail?id=".$order_goods['goods_id'];
  646. $product_infos['title'] = $order_goods['name'];
  647. $product_infos['head_img'] = tomedia($order_goods['goods_images']);
  648. $order_detail['product_infos'][] = $product_infos;
  649. }
  650. $pay_info = [];
  651. $pay_info['pay_method'] = '微信支付';
  652. $pay_info['prepay_id'] = $order_info['perpay_id'];
  653. $pay_info['prepay_time'] = date('Y-m-d H:i:s', $time );
  654. $order_detail['pay_info'] = $pay_info;
  655. $price_info = [];
  656. $price_info['order_price'] = $pay_total * 100;
  657. $price_info['freight'] = 0;
  658. $order_detail['price_info'] = $price_info;
  659. $need_data['order_detail'] = $order_detail;
  660. $need_data['delivery_detail'] = ['delivery_type' => 3];
  661. $address_info = [];
  662. $address_info['receiver_name'] = $order_info['shipping_name'];
  663. $address_info['detailed_address'] = $order_info['shipping_address'];
  664. $address_info['tel_number'] = $order_info['shipping_tel'];
  665. $need_data['address_info'] = $address_info;
  666. M('lionfish_comshop_order')->where( ['order_id' => $order_id ] )->save( ['from_type' => 'tradecomponts '] );
  667. //同步增加订单数据
  668. $access_token = $this->getMpAccessToken();
  669. $url = "https://api.weixin.qq.com/shop/order/add?access_token={$access_token}";
  670. $result_json = $this->sendhttps_post( $url , json_encode( $need_data ) );
  671. //$result = json_decode( $result_json, true );
  672. return ['code' => 0 , 'order_info' => $need_data ];
  673. }
  674. /**
  675. * @author yj
  676. * @desc 微信交易组件,订单支付成功
  677. * @param $order_id
  678. * @param string $action_type
  679. */
  680. public function orderPay( $order_id, $action_type = '1' )
  681. {
  682. $access_token = $this->getMpAccessToken();
  683. $url = "https://api.weixin.qq.com/shop/order/pay?access_token={$access_token}";
  684. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  685. $member_info = M('lionfish_comshop_member')->where(['member_id' => $order_info['member_id'] ])->find();
  686. $need_data = [];
  687. $need_data['out_order_id'] = $order_id;
  688. $need_data['openid'] = $member_info['we_openid'];
  689. $need_data['action_type'] = $action_type;
  690. $need_data['action_remark'] = '';
  691. $need_data['transaction_id'] = $order_info['transaction_id'];
  692. $need_data['pay_time'] = date('Y-m-d H:i:s', $order_info['pay_time'] );
  693. $result_json = $this->sendhttps_post( $url , json_encode( $need_data ) );
  694. }
  695. /**
  696. * @author yj
  697. * @desc 检测是否开启商品组件功能模块
  698. * @param $goods_id
  699. * @return int
  700. */
  701. public function checkGoodsIsTradeComponts( $goods_id )
  702. {
  703. $isopen_tradecomponts = D('Home/Front')->get_config_by_name('isopen_tradecomponts');
  704. $isopen_tradecomponts = !isset($isopen_tradecomponts) || $isopen_tradecomponts == 0 ? 0 : 1;
  705. if( $isopen_tradecomponts == 0 )
  706. {
  707. return 0;
  708. }
  709. $info = M('lionfish_comshop_goods_tradecomponts')->where( ['goods_id' => $goods_id] )->find();
  710. if( !empty($info) )
  711. {
  712. return 1;
  713. }else{
  714. return 0;
  715. }
  716. }
  717. }
  718. ?>