Order.php 27 KB

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