Order.php 26 KB

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