MpModifyTradeCompontsModel.class.php 31 KB

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