Order.php 26 KB

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