Order.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\library\AliPay;
  4. use app\common\library\Shande;
  5. use app\common\library\ShandeRapid;
  6. use think\cache\driver\Redis;
  7. use think\Db;
  8. use think\Exception;
  9. use EasyWeChat\Factory;
  10. use think\Session;
  11. use function Sodium\add;
  12. /**
  13. * @title 订单
  14. * @controller Order
  15. * @group base
  16. */
  17. class Order extends Base
  18. {
  19. public function initialize()
  20. {
  21. parent::initialize();
  22. parent::check_login();
  23. }
  24. /**
  25. * @title 生成订单(立即购买 )
  26. * @desc 生成订单(立即购买 )
  27. * @author Gavin
  28. * @url /api/Order/createOrder
  29. * @method POST
  30. * @header name:Authorization require:1 desc:Token
  31. * @param name:id type:int require:1 default:-- desc:藏品id
  32. * @param name:num type:int require:1 default:1 desc:数量
  33. * @param name:pay_type type:string require:1 default:wx desc:wx:微信zfb:支付宝wallet:钱包余额sd:杉德h5,sd_rapid:杉德快捷支付
  34. * @param name:from type:string require:1 default:wx desc:wx:微信公众号h5:网页【微信支付用的着,其他支付忽略】
  35. *
  36. * @return name:order_no type:int require:0 default:0 desc:订单号
  37. * @return name:pay type:string require:0 default:0 desc:支付信息
  38. */
  39. public function createOrder()
  40. {
  41. if (redisSetNx('createOrder'.$this->uid,3)) {
  42. $id = input('id');
  43. $num = input('num',1);
  44. $pay_type = input('pay_type','wx');
  45. $from = input('from','wx');
  46. if (!$id || $num <= 0) $this->error('参数错误');;
  47. $user = getMemberInfoHash($this->uid); //获取用户信息
  48. if ($user['is_auth']==0) $this->error('请实名认证后购买!');
  49. $coll_info = getCollectionInfoHash($id);
  50. if ($coll_info['is_deleted']==1 || $coll_info['status']==0) $this->error('藏品已下架');
  51. // 抽签发行方式验证是否中签
  52. if($coll_info['issue_mode'] == 2){
  53. $check_redis = new Redis();
  54. $luck_draw = $check_redis->get('lucky_draw_'.$id);
  55. if(!$luck_draw) $this->error('抽签未出结果');
  56. $luck_draw = json_decode($luck_draw,true);
  57. if(!in_array($this->uid,$luck_draw)) $this->error('没有中签');
  58. }
  59. $inventory = getCollectionInventory($id);
  60. if ($inventory<1) $this->error('已售罄');
  61. if ($inventory<$num) $this->error('库存不足');
  62. // 验证产品赋能优先购
  63. $set_time = $coll_info['sell_time'];
  64. $priority = false;
  65. if($coll_info['issue_mode'] == 1) {
  66. $priority = checkMemberPriority($this->uid,$coll_info['id']);
  67. if($priority && isset($coll_info['before_time'])){
  68. $sell_time = strtotime($coll_info['sell_time'])-($coll_info['before_time'] * 60);
  69. if ($sell_time <= time()) $info['state'] = 1;
  70. $coll_info['sell_time'] = date('Y-m-d H:i:s',$sell_time);
  71. }
  72. }
  73. $sell_time = strtotime($coll_info['sell_time']);
  74. if ($sell_time>time()) $this->error('商品还未开始售卖!请耐心等待');
  75. //获取用户已经购买数量
  76. $userByCount = getByCount($this->uid,$id);
  77. // 设置了限购数量 && 购买的数量达到了限购数量 && 未到正式开售时间
  78. if($priority && $priority !== true && $userByCount + $num > $priority && strtotime($set_time) > time()) $this->error('最多提前购买'.intval($priority).'个');
  79. if ($coll_info['buy_count']<($userByCount+$num)) $this->error('每人限购'.$coll_info['buy_count'].'个');
  80. //获取是否已经铸造hash
  81. $hashCount = getLenCollection($id);
  82. if ((!$hashCount || $hashCount<$num) && $coll_info['type'] != 3) $this->error('hash未铸造,无法购买');
  83. if($pay_type == 'wx'){
  84. if ($from=='wx' && !$user['openid']) $this->error('微信未授权,无法购买');
  85. }
  86. if ($pay_type=='zfb') $this->error('支付宝暂未开通');
  87. $total_fee = bcmul($coll_info['price'],$num,2);
  88. if($pay_type == 'wallet' && $user['money'] < $total_fee) $this->error('余额不足');
  89. //先减掉库存
  90. loseCollectionInventory($id,$num);
  91. //先增加购买数量
  92. IncrByCount($this->uid,$id,$num);
  93. $order_no = get_order_sn();
  94. $total_price = $total_fee;//总金额
  95. $redis_data = [
  96. 'mid'=>$this->uid,
  97. 'c_id'=>$id,
  98. 'order_no'=>$order_no,
  99. 'inventory'=>$coll_info['inventory'],
  100. 'num'=>$num,
  101. 'pro_info'=>json_encode($coll_info),
  102. 'status'=>0,
  103. 'create_at'=>date('Y-m-d H:i:s'),
  104. 'total_price'=>$total_price,
  105. 'pay_price'=>$total_fee,
  106. 'pay_type'=>$pay_type,
  107. ];
  108. $com = true;
  109. $retrun_data['order_no'] = $order_no;
  110. $retrun_data['pay'] = '';
  111. $retrun_data['user_id'] = $this->uid;
  112. if ($com){
  113. $redis = new Redis();
  114. //收集下单用户id
  115. setCollectionBuyUser($this->uid);
  116. $redis->hMSet('order_not_pay_'.$this->uid,[$order_no=>json_encode($redis_data)]); //存入redis
  117. DelRedisSetNx('createOrder'.$this->uid);
  118. $this->success('成功',$retrun_data);
  119. }else{
  120. //加上库存
  121. addCollectionInventory($id,$num);
  122. //减少用户购买数量
  123. DecrByCount($this->uid,$id,$num);
  124. DelRedisSetNx('createOrder'.$this->uid);
  125. $this->error('服务器繁忙,请稍后重试');
  126. }
  127. }else{
  128. $this->error('服务器繁忙,请稍后重试');
  129. }
  130. }
  131. /**
  132. * @title 我的订单-待支付、已购买
  133. * @desc 我的订单-待支付、已购买
  134. * @author Gavin
  135. * @url /api/Orde/getMyOrderList
  136. * @method POST
  137. * @header name:Authorization require:1 desc:Token
  138. * @param name:status type:int : default:0 desc:0:待支付1:已购买
  139. * @param name:page type:int : default:1 desc:页数
  140. * @param name:page_num type:int : default:20 desc:每页数
  141. *
  142. * @return name:order_no type:string default:-- desc:订单号
  143. * @return name:num type:int default:-- desc:数量
  144. * @return name:pay_price type:string default:-- desc:订单金额
  145. * @return name:status type:int default:-- desc:类型0:待支付1:已支付
  146. * @return name:cancel_time type:string default:-- desc:待支付自动取消时间
  147. * @return name:pay_type type:string default:-- desc:支付方式wx:微信zfb:支付宝
  148. * @return name:create_at type:string default:-- desc:创建时间
  149. * @return name:pro_info@name type:string default:-- desc:藏品名称
  150. * @return name:pro_info@cover type:string default:-- desc:藏品图片
  151. * @return name:pro_info@price type:string default:-- desc:藏品单价
  152. * @return name:pro_info@auth_img type:string default:-- desc:藏品作者头像
  153. * @return name:pro_info@auth_name type:string default:-- desc:藏品作者名称
  154. */
  155. public function getMyOrderList(){
  156. $status = input('status',0);
  157. if ($status==0){
  158. $redis = new Redis();
  159. $key = 'order_not_pay_'.$this->uid;
  160. $count = $redis->hGetLen($key);
  161. $list = $redis->hGetvals($key);
  162. if ($list){
  163. //自动取消分钟数
  164. $cancel_time = getCancelTime();
  165. foreach ($list as $k=>&$v){
  166. $info = json_decode($v,true);
  167. $info['pro_info'] = json_decode($info['pro_info'],true);
  168. $info['cancel_time'] = date('Y-m-d H:i:s',strtotime($info['create_at'])+($cancel_time*60));
  169. $info['create_int'] = strtotime($info['create_at']);
  170. $list[$k] = $info;
  171. }
  172. array_multisort(array_column($list,'create_int'),SORT_DESC,$list);
  173. }
  174. }else{
  175. $where = [
  176. 'is_deleted'=>0,
  177. 'status'=>$status,
  178. 'mid'=>$this->uid
  179. ];
  180. $count = Db::name('store_order')->where($where)->count();
  181. $list = Db::name('store_order')
  182. ->where($where)
  183. ->field('id,c_id,order_no,num,pro_info,status,create_at,pay_price,pay_type')
  184. ->order('id desc')
  185. ->limit($this->off_set,$this->page_num)
  186. ->select();
  187. foreach ($list as &$v){
  188. $v['pro_info'] = json_decode($v['pro_info'],true);
  189. }
  190. }
  191. $this->success('成功',compact('count','list'));
  192. }
  193. /**
  194. * @title 待支付、已购买订单详情
  195. * @desc 待支付、已购买订单详情
  196. * @author Gavin
  197. * @url /api/Order/MyOrderListDetail
  198. * @method POST
  199. * @header name:Authorization require:1 desc:Token
  200. * @param name:order_no type:string default:0 desc:订单号
  201. * @param name:type type:int default:1 desc:1:待支付2:已支付
  202. *
  203. * @return name:order_no type:string default:-- desc:订单号
  204. * @return name:num type:int default:-- desc:数量
  205. * @return name:pay_price type:string default:-- desc:订单金额
  206. * @return name:status type:int default:-- desc:类型0:待支付1:已支付
  207. * @return name:cancel_time type:string default:-- desc:待支付自动取消时间
  208. * @return name:create_at type:string default:-- desc:创建时间
  209. * @return name:pay_at type:string default:-- desc:支付时间
  210. * @return name:pay_type type:string default:-- desc:支付方式wx:微信zfb:支付宝,sd杉德,sd_rapid:杉德快捷支付
  211. * @return name:pro_info@name type:string default:-- desc:藏品名称
  212. * @return name:pro_info@cover type:string default:-- desc:藏品图片
  213. * @return name:pro_info@price type:string default:-- desc:藏品单价
  214. * @return name:pro_info@auth_img type:string default:-- desc:藏品作者头像
  215. * @return name:pro_info@auth_name type:string default:-- desc:藏品作者名称
  216. */
  217. public function MyOrderListDetail(){
  218. $order_no = input('order_no');
  219. $type = input('type',1);
  220. if (!$order_no) $this->error('参数错误');
  221. if ($type==1){
  222. $redis = new Redis();
  223. $key = 'order_not_pay_'.$this->uid;
  224. $order = $redis->hGet($key,$order_no);
  225. $order = json_decode($order,true);
  226. }else{
  227. $order = Db::name('store_order')
  228. ->where('order_no',$order_no)
  229. ->where('mid',$this->uid)
  230. ->where('is_deleted',0)
  231. ->find();
  232. }
  233. if (!$order) $this->error('订单不存在');
  234. $order['pro_info'] = json_decode($order['pro_info'],true);
  235. //自动取消分钟数
  236. $cancel_time = getCancelTime();
  237. if ($order['status']==0){
  238. $order['cancel_time'] = date('Y-m-d H:i:s',strtotime($order['create_at'])+($cancel_time*60));
  239. }
  240. $this->success('成功',$order);
  241. }
  242. /**
  243. * @title 待支付订单支付
  244. * @desc 待支付订单支付
  245. * @author Gavin
  246. * @url /api/Order/payOrder
  247. * @method POST
  248. * @header name:Authorization require:1 desc:Token
  249. * @param name:order_no type:string require:1 default:-- desc:订单号
  250. * @param name:from type:string require:1 default:wx desc:wx:微信公众号,h5:网页:wallet余额,sd:杉德h5,sd_rapid:杉德快捷支付
  251. *
  252. * @return name:order_no type:int require:0 default:0 desc:订单号
  253. * @return name:pay type:string require:0 default:0 desc:支付信息
  254. * @return name:order_no type:string default:0 desc:支付单号(sd)
  255. * @return name:extend type:int default:0 desc:用户id(sd)
  256. * @return name:pay type:array default:0 desc:支付信息(sd)
  257. * @return name:pay.body type:array default:0 desc:支付信息(sd)
  258. * @return name:pay.totalAmount type:string default:0 desc:支付金额【000000010000是100元】(sd)
  259. * @return name:pay.orderCode type:string default:0 desc:支付单号(sd)
  260. * @return name:pay.credential type:string default:0 desc:正书(sd)
  261. */
  262. public function payOrder(){
  263. $user = getMemberInfoHash($this->uid); //获取用户信息
  264. $order_no = input('order_no'); //订单号
  265. $from = input('from','wx');
  266. if (!$order_no) $this->error('参数错误');
  267. $redis = new Redis();
  268. $key = 'order_not_pay_'.$this->uid;
  269. $order = $redis->hGet($key,$order_no);
  270. if (!$order) $this->error('订单不存在'.$this->uid);
  271. $order = json_decode($order,true);
  272. if ($order['status']!=0) $this->error('订单已支付或已取消');
  273. $CancelTime = getCancelTime();
  274. if (strtotime($order['create_at']) + $CancelTime * 60 < time()) $this->error('订单超时');
  275. $order_no = $order['order_no'];
  276. $total_fee = $order['pay_price'];
  277. $pay_type = $order['pay_type'];
  278. $body = '象链数藏购买藏品';
  279. $com = true;
  280. $retrun_data = [];
  281. switch ($pay_type){
  282. case 'wx':
  283. $config = retrunWxConfig();
  284. $total_fee = $total_fee * 100;
  285. $config['notify_url'] = 'https://'.$_SERVER['HTTP_HOST'].'/index.php/api/Pay/WxOrderNotify';
  286. $app = Factory::payment($config);
  287. $post_data = [
  288. 'body' => $body,
  289. 'out_trade_no' => $order_no,
  290. 'total_fee' => $total_fee,
  291. 'attach'=>$this->uid, //自定义传值
  292. ];
  293. //trade_type SAPI--JSAPI支付(或小程序支付)、NATIVE--Native支付、APP--app支付,MWEB--H5支付
  294. if ($from=='wx'){
  295. $post_data['openid'] = $user['openid'];
  296. $post_data['trade_type'] = 'JSAPI';
  297. }elseif ($from=='h5'){
  298. $post_data['trade_type'] = 'MWEB';
  299. }
  300. $result = $app->order->unify($post_data);
  301. if ($result['return_msg']=='OK'){
  302. if ($result['result_code']=='FAIL'){
  303. $com = false;
  304. }else{
  305. $order1 = $app->jssdk->bridgeConfig($result['prepay_id']);//执行二次签名返回参数
  306. $redis_data['wx_order'] = $order1;
  307. $retrun_data['order_no'] = $order_no;
  308. if($from == 'h5'){
  309. $retrun_data['pay'] = $result['mweb_url'];
  310. }else{
  311. $retrun_data['pay'] = json_decode($order1,true);
  312. }
  313. }
  314. }else{
  315. $com = false;
  316. }
  317. break;
  318. case 'zfb':
  319. $zfb = new AliPay();
  320. $notify_url = $this->request->root(true).'/index.php/api/Pay/alipayOrderNotify?attach='.$this->uid;//回调地址
  321. $order = $zfb->ali_pay_pc($body, $total_fee, $order_no, $notify_url,'https://'.$_SERVER['HTTP_HOST'].'/h5/pages/mine/order-list?num=1');//调用支付宝支付的方法
  322. $retrun_data['order_no'] = $order_no;
  323. $retrun_data['pay'] = $order;
  324. break;
  325. case 'sd':
  326. $client = new Shande();
  327. $notify_url = 'https://'.$_SERVER['HTTP_HOST'].'/api/Pay/shandeOrderNotify';//回调地址
  328. $total_fee = $total_fee*100;
  329. $lenth = strlen($total_fee);
  330. $total_fee = get0number($lenth).$total_fee;
  331. $result = $client->orderPay($order_no.'S'.$this->uid,$total_fee,$body,$notify_url,'https://'.$_SERVER['HTTP_HOST'].'/h5/pages/mine/mine',$user['bank_num']);
  332. $retrun_data['order_no'] = $order_no;
  333. $retrun_data['extend'] = $this->uid;
  334. $retrun_data['pay'] = json_decode($result['data'],true);
  335. if( $retrun_data['pay']['head']['respCode'] != '00000')$this->error($retrun_data['pay']['head']['respMsg'].'请重新下单');
  336. break;
  337. case 'wallet':
  338. Db::startTrans();
  339. try{
  340. if($user['money'] < $total_fee) throw new Exception('余额不足');
  341. $pay_res = (new Pay())->dealData(['out_trade_no' => $order_no,'attach'=>$this->uid]);
  342. if(!$pay_res) throw new Exception('支付失败');
  343. $order_id = Db::name('store_order_info')->where(['order_no'=>$order_no])->value('id');
  344. memberMoneyChange($total_fee,3,$this->uid,'余额支付',0,$order_id,4);
  345. setMemberInfoHash($this->uid);
  346. Db::commit();
  347. }catch (\Exception $e){
  348. $com = false;
  349. $msg= $e->getMessage();
  350. Db::rollback();
  351. }
  352. $retrun_data = null;
  353. break;
  354. case 'sd_rapid' :
  355. if(!$user['true_name'] || !$user['id_card']) $this->error('请实名认证,在进行订单支付');
  356. $rapid = new ShandeRapid();
  357. $notify_url = 'https://'.$_SERVER['HTTP_HOST'].'/api/Pay/shandeOrderNotify';//回调地址
  358. //$return_url = 'https://'.$_SERVER['HTTP_HOST'].'/h5/pages/mine/mine';//回调地址
  359. $return_url ='https://'.$_SERVER['HTTP_HOST']."/h5/pages/mine/mine?id={$order['c_id']}&orderNo={$order_no}";//回调地址
  360. $pay_extra = json_encode(['userId'=>"$this->uid",'userName'=>$user['true_name'],'idCard'=>$user['id_card']]);
  361. $pay_url = $rapid->payOrder($order_no.'S'.$this->uid,$total_fee,$notify_url,$return_url,$pay_extra,$body);
  362. parse_str(parse_url($pay_url)['query'],$pay_query);
  363. $retrun_data['parse_url'] = parse_url($pay_url)['query'];
  364. $retrun_data['order_no'] = $order_no;
  365. $retrun_data['extend'] = $this->uid;
  366. $retrun_data['pay_url'] = $pay_url;
  367. $retrun_data['pay_query'] = $pay_query;
  368. break;
  369. }
  370. if ($com){
  371. if($pay_type == 'wallet')$this->success('支付成功');
  372. $this->success('成功',$retrun_data);
  373. }else{
  374. if($pay_type == 'wallet')$this->error($msg);
  375. $this->error('调起支付失败,请稍后重试');
  376. }
  377. }
  378. /**
  379. * @title 取消订单
  380. * @desc 取消订单
  381. * @author Gavin
  382. * @url /api/Order/cancelOrder
  383. * @method POST
  384. * @header name:Authorization require:1 desc:Token
  385. * @param name:order_no type:string require:1 default:-- desc:订单号
  386. */
  387. public function cancelOrder(){
  388. $order_no = input('order_no');
  389. if (!$order_no) $this->error('参数错误');
  390. $redis = new Redis();
  391. $key = 'order_not_pay_'.$this->uid;
  392. $order = $redis->hGet($key,$order_no);
  393. if (!$order) $this->error('订单不存在');
  394. $order = json_decode($order,true);
  395. if ($order['status']!=0) $this->error('订单已支付或已取消');
  396. $com = true;
  397. Db::startTrans();
  398. try {
  399. $order['status'] = 2;
  400. $order['cancel_at'] = date('Y-m-d H:i:s');
  401. $order['cancel_state'] = 2;
  402. Db::name('store_order')->insert($order);
  403. Db::commit();
  404. }catch (\Exception $e){
  405. $com=false;
  406. Db::rollback();
  407. }
  408. if ($com){
  409. //加上库存
  410. addCollectionInventory($order['c_id'],$order['num']);
  411. //减少用户购买数量
  412. DecrByCount($this->uid,$order['c_id'],$order['num']);
  413. //删除数据
  414. $redis->hdel($key,$order_no);
  415. $this->success('取消成功');
  416. }else{
  417. $this->error('取消失败,请稍后重试');
  418. }
  419. }
  420. /**
  421. * @title 我的订单-转赠
  422. * @desc 我的订单-转赠
  423. * @author Gavin
  424. * @url /api/Order/getMySendList
  425. * @method POST
  426. * @header name:Authorization require:1 desc:Token
  427. * @param name:page type:int : default:1 desc:页数
  428. * @param name:page_num type:int : default:20 desc:每页数
  429. *
  430. * @return name:order_no type:string default:-- desc:订单号
  431. * @return name:over_time type:string default:-- desc:转赠时间
  432. * @return name:status type:int default:-- desc:类型2:赠出3:获赠
  433. * @return name:send_name type:string default:-- desc:转赠者/受赠者
  434. * @return name:collectors_hash type:string default:-- desc:hash
  435. * @return name:pro_info@name type:string default:-- desc:藏品名称
  436. * @return name:pro_info@price type:string default:-- desc:藏品价格
  437. * @return name:pro_info@price type:string default:-- desc:藏品单价
  438. * @return name:pro_info@auth_img type:string default:-- desc:藏品作者头像
  439. * @return name:pro_info@auth_name type:string default:-- desc:藏品作者名称
  440. */
  441. public function getMySendList(){
  442. $where = [
  443. 'mid'=>$this->uid,
  444. ];
  445. $count = Db::name('store_order_info')->where($where)->whereIn('status','2,3')->count();
  446. $list = Db::name('store_order_info')
  447. ->where($where)
  448. ->whereIn('status','2,3')
  449. ->field('id,order_no,pro_info,over_time,create_at,status,to_mid,collectors_hash')
  450. ->order('over_time desc ,id desc')
  451. ->limit($this->off_set,$this->page_num)
  452. ->select();
  453. foreach ($list as &$v){
  454. $v['pro_info'] = json_decode($v['pro_info'],true);
  455. $v['send_name'] = Db::name('store_member')->where('id',$v['to_mid'])->value('name');
  456. }
  457. $this->success('成功',compact('count','list'));
  458. }
  459. /**
  460. * @title 转赠订单详情
  461. * @desc 转赠订单详情
  462. * @author Gavin
  463. * @url /api/Order/getMySendListDetail
  464. * @method POST
  465. * @header name:Authorization require:1 desc:Token
  466. * @param name:order_id type:int : default:1 desc:订单ID
  467. *
  468. * @return name:order_no type:string default:-- desc:订单号
  469. * @return name:over_time type:string default:-- desc:转赠时间
  470. * @return name:status type:int default:-- desc:类型2:赠出3:获赠
  471. * @return name:send_name type:string default:-- desc:转赠者/受赠者
  472. * @return name:collectors_hash type:string default:-- desc:hash
  473. * @return name:pro_info@name type:string default:-- desc:藏品名称
  474. * @return name:pro_info@price type:string default:-- desc:藏品价格
  475. * @return name:pro_info@price type:string default:-- desc:藏品单价
  476. * @return name:pro_info@auth_img type:string default:-- desc:藏品作者头像
  477. * @return name:pro_info@auth_name type:string default:-- desc:藏品作者名称
  478. */
  479. public function getMySendListDetail(){
  480. $order_id = input('order_id'); //订单id
  481. if (!$order_id) $this->error('参数错误');
  482. $order = Db::name('store_order_info')
  483. ->where('id',$order_id)
  484. ->where('mid',$this->uid)
  485. ->find();
  486. if (!$order) $this->error('订单不存在');
  487. $order['pro_info'] = json_decode($order['pro_info'],true);
  488. $order['num'] = 1;
  489. $order['pay_price'] = 0;
  490. $order['send_name'] = '--';
  491. if($order['to_mid']) $order['send_name'] = Db::name('store_member')->where('id',$order['to_mid'])->value('name');
  492. $this->success('成功',$order);
  493. }
  494. function savetest($order_no){
  495. $result['out_trade_no'] = $order_no;
  496. $order = Db::name('store_order')->where('order_no',$result['out_trade_no'])->find();
  497. if ($order['status']==0){
  498. Db::startTrans();
  499. try {
  500. Db::name('store_order')
  501. ->where('order_no',$result['out_trade_no'])
  502. ->update(['status'=>1,'pay_at'=>date('Y-m-d H:i:s'),'return_success_info'=>json_encode($result,true)]);
  503. $array = [];
  504. for ($i=0;$i<$order['num'];$i++){
  505. //获取排名
  506. $rank = getRanking($order['c_id']);
  507. $tag = getTag($order['c_id'],$rank,$order['inventory']);
  508. saveRanking($order['c_id']);
  509. $company = '象寻数字科技(上海)有限公司';
  510. $company_hash = '';
  511. $company_hash_time = '';
  512. $collectors_hash = '';
  513. $date = [
  514. 'order_id'=>$order['id'],
  515. 'order_no'=>get_order_sn(),
  516. 'tag'=>$tag,
  517. 'mid'=>$order['mid'],
  518. 'pro_info'=>$order['pro_info'],
  519. 'company'=>$company,
  520. 'company_hash'=>$company_hash,
  521. 'company_hash_time'=>$company_hash_time,
  522. 'collectors_hash'=>$collectors_hash,
  523. 'collectors_hash_time'=>date('Y-m-d H:i:s')
  524. ];
  525. $array[] = $date;
  526. }
  527. Db::name('store_order_info')->insertAll($array);
  528. Db::commit();
  529. // return true;
  530. } catch (\Exception $e){
  531. Db::rollback();
  532. //return false;
  533. }
  534. }
  535. }
  536. }