Order.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\library\AliPay;
  4. use app\common\library\AliPay3;
  5. use app\common\library\HuijuH5Pay;
  6. use app\common\library\HuijuKjPay;
  7. use app\common\library\Jiyan;
  8. use think\cache\driver\Redis;
  9. use think\Db;
  10. use think\Exception;
  11. use EasyWeChat\Factory;
  12. use think\Session;
  13. use function Sodium\add;
  14. /**
  15. * @title 订单
  16. * @controller GoodsOrder
  17. * @group base
  18. */
  19. class Order extends Base
  20. {
  21. public function initialize()
  22. {
  23. parent::initialize();
  24. parent::check_login();
  25. }
  26. /**
  27. * @title 生成订单(立即购买 )
  28. * @desc 生成订单(立即购买 )
  29. * @author Gavin
  30. * @url /api/Order/createOrder
  31. * @method POST
  32. * @header name:Authorization require:1 desc:Token
  33. * @param name:id type:int require:1 default:-- desc:藏品id
  34. * @param name:num type:int require:1 default:1 desc:数量
  35. * @param name:pay_type type:string require:1 default:wx desc:wx:微信zfb:支付宝
  36. * @param name:from type:string require:1 default:wx desc:wx:微信公众号h5:网页
  37. *
  38. * @return name:order_no type:int require:0 default:0 desc:订单号
  39. * @return name:pay type:string require:0 default:0 desc:支付信息
  40. */
  41. public function createOrder()
  42. {
  43. $redis = new Redis([ 'select'=> 2]);
  44. $redis_value = $redis->get('order_buy'.$this->uid);
  45. if ($redis_value){
  46. $this->error('请求过快,请稍后重试');
  47. }else{
  48. $redis->set('order_buy'.$this->uid,1,1);
  49. }
  50. $id = input('id');
  51. $num = input('num',1);
  52. $pay_type = input('pay_type','wx');
  53. $from = input('from','wx');
  54. if (!$id || !$num) $this->error('参数错误');
  55. //极验数据
  56. // $lot_number = input('lot_number');
  57. // $captcha_output = input('captcha_output');
  58. // $pass_token = input('pass_token');
  59. // $gen_time = input('gen_time');
  60. // if (!$lot_number || !$captcha_output || !$pass_token || !$gen_time) $this->error('参数错误');
  61. //
  62. // $jy = new Jiyan();
  63. // $result = $jy->jy($lot_number,$captcha_output,$pass_token,$gen_time,2);
  64. // if ($result['result']=='fail') $this->error('校验失败,请稍后重试');
  65. $user = getMemberInfoHash($this->uid); //获取用户信息
  66. if ($user['is_auth']==0) $this->error('请实名认证后购买!');
  67. $coll_info = getCollectionInfoHash($id);
  68. if ($coll_info['is_deleted']==1 || $coll_info['status']==0) $this->error('藏品已下架');
  69. $inventory = getCollectionInventory($id);
  70. if ($inventory<$num) $this->error('库存不足');
  71. if ($inventory<1) $this->error('还有未支付的订单,您有可能捡漏哦!');
  72. if (!$coll_info['sold_out']) $this->error('已售罄');
  73. $cards = checkUseSnapcard($this->uid,$id,$coll_info['sell_time']);
  74. if (!$cards){
  75. if ($coll_info['state']!=1) $this->error('状态错误');
  76. $sell_time = strtotime($coll_info['sell_time']);
  77. if ($sell_time>time()) $this->error('商品还未开始售卖!请耐心等待');
  78. }
  79. if ($pay_type=='yhkj'){
  80. if (!$user['hj_pay_status']) $this->error('请签约银行卡后购买');
  81. }
  82. //获取用户已经购买数量
  83. $userByCount = getByCount($this->uid,$id);
  84. if ($coll_info['buy_count']<($userByCount+$num)) $this->error('每人限购'.$coll_info['buy_count'].'个');
  85. //获取是否已经铸造hash
  86. //$hashCount = getLenCollection($id);
  87. $hash = Db::name('hash2')->where('goods_id',$id)->where('success',1)->count();
  88. if (!$hash) $this->error('nft未上架,无法购买');
  89. // if (!$hashCount || $hashCount<$num) $this->error('hash未铸造,无法购买');
  90. if ($from=='wx'){
  91. if (!$user['openid']) $this->error('微信未授权,无法购买');
  92. }
  93. //先减掉库存
  94. loseCollectionInventory($id,$num);
  95. //先增加购买数量
  96. IncrByCount($this->uid,$id,$num);
  97. $order_no = get_order_sn();
  98. $total_fee = bcmul($coll_info['price'],$num,2);
  99. $redis_data = [
  100. 'mid'=>$this->uid,
  101. 'c_id'=>$id,
  102. 'order_no'=>$order_no,
  103. 'inventory'=>$coll_info['inventory'],
  104. 'num'=>$num,
  105. 'pro_info'=>json_encode($coll_info),
  106. 'status'=>0,
  107. 'create_at'=>date('Y-m-d H:i:s'),
  108. 'pay_price'=>$total_fee,
  109. 'pay_type'=>$pay_type
  110. ];
  111. $com = true;
  112. $retrun_data['order_no'] = $order_no;
  113. $retrun_data['pay'] = '';
  114. if ($com){
  115. //更新抢购卡使用记录
  116. if ($cards){
  117. Db::name('store_snap_card_log')->where('id',$cards[0])->update(['is_use'=>2,'update_at'=>date('Y-m-d H:i:s')]);
  118. }
  119. $redis = new Redis();
  120. //收集下单用户id
  121. setCollectionBuyUser($this->uid);
  122. $redis->hMSet('order_not_pay_'.$this->uid,[$order_no=>json_encode($redis_data,true)]); //存入redis
  123. $this->success('成功',$retrun_data);
  124. }else{
  125. //加上库存
  126. addCollectionInventory($id,$num);
  127. //减少用户购买数量
  128. DecrByCount($this->uid,$id,$num);
  129. $this->error('服务器繁忙,请稍后重试');
  130. }
  131. }
  132. /**
  133. * @title 我的订单-待支付、已购买
  134. * @desc 我的订单-待支付、已购买
  135. * @author Gavin
  136. * @url /api/Order/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. $list[$k] = $info;
  171. }
  172. }
  173. }else{
  174. $where = [
  175. 'is_deleted'=>0,
  176. 'status'=>$status,
  177. 'mid'=>$this->uid
  178. ];
  179. $count = Db::name('store_order')->where($where)->count();
  180. $list = Db::name('store_order')
  181. ->where($where)
  182. ->field('id,c_id,order_no,num,pro_info,status,create_at,pay_price,pay_type')
  183. ->order('id desc')
  184. ->limit($this->off_set,$this->page_num)
  185. ->select();
  186. foreach ($list as &$v){
  187. $v['pro_info'] = json_decode($v['pro_info'],true);
  188. }
  189. }
  190. $this->success('成功',compact('count','list'));
  191. }
  192. /**
  193. * @title 待支付、已购买订单详情
  194. * @desc 待支付、已购买订单详情
  195. * @author Gavin
  196. * @url /api/Order/MyOrderListDetail
  197. * @method POST
  198. * @header name:Authorization require:1 desc:Token
  199. * @param name:order_no type:string default:0 desc:订单号
  200. * @param name:type type:int default:1 desc:1:待支付2:已支付
  201. *
  202. * @return name:order_no type:string default:-- desc:订单号
  203. * @return name:num type:int default:-- desc:数量
  204. * @return name:pay_price type:string default:-- desc:订单金额
  205. * @return name:status type:int default:-- desc:类型0:待支付1:已支付
  206. * @return name:cancel_time type:string default:-- desc:待支付自动取消时间
  207. * @return name:create_at type:string default:-- desc:创建时间
  208. * @return name:pay_at type:string default:-- desc:支付时间
  209. * @return name:pay_type type:string default:-- desc:支付方式wx:微信zfb:支付宝
  210. * @return name:pro_info@name type:string default:-- desc:藏品名称
  211. * @return name:pro_info@cover type:string default:-- desc:藏品图片
  212. * @return name:pro_info@price type:string default:-- desc:藏品单价
  213. * @return name:pro_info@auth_img type:string default:-- desc:藏品作者头像
  214. * @return name:pro_info@auth_name type:string default:-- desc:藏品作者名称
  215. */
  216. public function MyOrderListDetail(){
  217. $order_no = input('order_no');
  218. $type = input('type',1);
  219. if (!$order_no) $this->error('参数错误');
  220. if ($type==1){
  221. $redis = new Redis();
  222. $key = 'order_not_pay_'.$this->uid;
  223. $order = $redis->hGet($key,$order_no);
  224. $order = json_decode($order,true);
  225. }else{
  226. $order = Db::name('store_order')
  227. ->where('order_no',$order_no)
  228. ->where('mid',$this->uid)
  229. ->where('is_deleted',0)
  230. ->find();
  231. }
  232. if (!$order) $this->error('订单不存在');
  233. $order['pro_info'] = json_decode($order['pro_info'],true);
  234. //自动取消分钟数
  235. $cancel_time = getCancelTime();
  236. if ($order['status']==0){
  237. $order['cancel_time'] = date('Y-m-d H:i:s',strtotime($order['create_at'])+($cancel_time*60));
  238. }
  239. $this->success('成功',$order);
  240. }
  241. /**
  242. * 银行卡快捷支付发送短信
  243. * @url /api/Order/yhkjSms
  244. */
  245. public function yhkjSms(){
  246. //redis原子锁
  247. if (redisSetNx('yhkjSms'.$this->uid,3)){
  248. $user = getMemberInfoHash($this->uid); //获取用户信息
  249. $order_no = input('order_no'); //订单号
  250. if (!$order_no) $this->error('参数错误');
  251. $redis = new Redis();
  252. $key = 'order_not_pay_'.$this->uid;
  253. $order = $redis->hGet($key,$order_no);
  254. if (!$order) $this->error('订单不存在');
  255. $order = json_decode($order,true);
  256. if ($order['status']!=0) $this->error('订单已支付或已取消');
  257. $huiju = new HuijuKjPay();
  258. $order_nos = get_order_sn();
  259. $order['order_no'] = $order_nos;
  260. $redis->hMSet($key,[$order_nos=>json_encode($order,true)]); //存入redis
  261. //删除redis
  262. $redis->hdel($key,$order_no);
  263. $callback_url = 'http://'.$_SERVER['SERVER_NAME'].'/index.php/api/Pay/kuaijiePayNotify';//回调地址
  264. $result = $huiju->paySms($order_nos,$order['pay_price'],'一级市场购买藏品',$this->uid,$callback_url,$user['hj_pay_bank_card']);
  265. if ($result['resp_codo']=='SUCCESS'){
  266. if ($result['biz_code']=='JS000000'){
  267. $data = json_decode($result['data'],true);
  268. if ($data['order_status']=='P3000'){
  269. DelRedisSetNx('yhkjSms'.$this->uid);
  270. $this->success('发送成功',$result);
  271. }else{
  272. DelRedisSetNx('yhkjSms'.$this->uid);
  273. $this->error($data['err_msg']);
  274. }
  275. }else{
  276. DelRedisSetNx('yhkjSms'.$this->uid);
  277. $this->error($result['biz_msg']);
  278. }
  279. }else{
  280. DelRedisSetNx('yhkjSms'.$this->uid);
  281. $this->error('发送失败');
  282. }
  283. }else{
  284. $this->error('请求过快');
  285. }
  286. }
  287. /**
  288. * @title 待支付订单支付
  289. * @desc 待支付订单支付
  290. * @author Gavin
  291. * @url /api/Order/payOrder
  292. * @method POST
  293. * @header name:Authorization require:1 desc:Token
  294. * @param name:order_no type:string require:1 default:-- desc:订单号
  295. * @param name:from type:string require:1 default:wx desc:wx:微信公众号h5:网页
  296. *
  297. * @return name:order_no type:int require:0 default:0 desc:订单号
  298. * @return name:pay type:string require:0 default:0 desc:支付信息
  299. */
  300. public function payOrder(){
  301. $user = getMemberInfoHash($this->uid); //获取用户信息
  302. $order_no = input('order_no'); //订单号
  303. $from = input('from','wx');
  304. if (!$order_no) $this->error('参数错误');
  305. $redis = new Redis();
  306. $key = 'order_not_pay_'.$this->uid;
  307. $order = $redis->hGet($key,$order_no);
  308. if (!$order) $this->error('订单不存在');
  309. $order = json_decode($order,true);
  310. if ($order['status']!=0) $this->error('订单已支付或已取消');
  311. $order_no = $order['order_no'];
  312. $total_fee = $order['pay_price'];
  313. $pay_type = $order['pay_type'];
  314. if ($pay_type=='yhkj'){
  315. $sms_code = input('sms_code');
  316. if (!$sms_code) $this->error('验证码为空');
  317. }
  318. $body = 'top艺术购买藏品';
  319. $com = true;
  320. switch ($pay_type){
  321. case 'wx':
  322. $config = retrunWxConfig();
  323. $total_fee = $total_fee * 100;
  324. $config['notify_url'] = $this->request->root(true).'/api/Pay/WxOrderNotify';
  325. $app = Factory::payment($config);
  326. $post_data = [
  327. 'body' => $body,
  328. 'out_trade_no' => $order_no,
  329. 'total_fee' => $total_fee,
  330. 'attach'=>$this->uid, //自定义传值
  331. ];
  332. //trade_type SAPI--JSAPI支付(或小程序支付)、NATIVE--Native支付、APP--app支付,MWEB--H5支付
  333. if ($from=='wx'){
  334. $post_data['openid'] = $user['openid'];
  335. $post_data['trade_type'] = 'JSAPI';
  336. }elseif ($from=='h5'){
  337. $post_data['trade_type'] = 'MWEB';
  338. }
  339. $result = $app->order->unify($post_data);
  340. if ($result['return_msg']=='OK'){
  341. if ($result['result_code']=='FAIL'){
  342. $com = false;
  343. }else{
  344. $order1 = $app->jssdk->bridgeConfig($result['prepay_id']);//执行二次签名返回参数
  345. $redis_data['wx_order'] = $order1;
  346. $retrun_data['order_no'] = $order_no;
  347. $retrun_data['pay'] = json_decode($order1,true);
  348. }
  349. }else{
  350. $com = false;
  351. }
  352. break;
  353. case 'zfb':
  354. $order_nos = get_order_sn();
  355. $order['order_no'] = $order_nos;
  356. $redis->hMSet($key,[$order_nos=>json_encode($order,true)]); //存入redis
  357. //存入redis
  358. $redis->hdel($key,$order_no);
  359. $zfb = new AliPay3();
  360. $notify_url = 'https://'.$_SERVER['SERVER_NAME'].'/index.php/api/Pay/alipayOrderNotify';//回调地址
  361. $callback_url = 'https://'.$_SERVER['SERVER_NAME'].'/pages/mine/order-list?num=1';
  362. $order = $zfb->aliPay($body,$total_fee,$order_nos,$notify_url,$this->uid,$callback_url);
  363. $retrun_data['order_no'] = $order_nos;
  364. $retrun_data['pay'] = $order['pay_url'];
  365. break;
  366. case 'ylh5':
  367. $order_nos = get_order_sn();
  368. $order['order_no'] = $order_nos;
  369. $redis->hMSet($key,[$order_nos=>json_encode($order,true)]); //存入redis
  370. //存入redis
  371. $redis->hdel($key,$order_no);
  372. $callback_url = 'http://'.$_SERVER['SERVER_NAME'].'/pages/mine/order-list?num=1';
  373. $huiju = new HuijuH5Pay();
  374. $notify_url = 'http://'.$_SERVER['SERVER_NAME'].'/index.php/api/Pay/ylOrderNotify';//回调地址
  375. $pro_info = json_decode($order['pro_info'],true);
  376. $result = $huiju->ylh5Pay($order_nos,$callback_url,$notify_url,$pro_info['name'],$total_fee,$this->uid,2);
  377. if ($result['ra_Code']=='100'){
  378. $retrun_data['order_no'] = $order_nos;
  379. $retrun_data['pay'] = $result['rc_Result'];
  380. }else{
  381. $com = false;
  382. }
  383. break;
  384. case 'zfbh5':
  385. $order_nos = get_order_sn();
  386. $order['order_no'] = $order_nos;
  387. $redis->hMSet($key,[$order_nos=>json_encode($order,true)]); //存入redis
  388. //存入redis
  389. $redis->hdel($key,$order_no);
  390. $callback_url = 'http://'.$_SERVER['SERVER_NAME'].'/pages/mine/order-list?num=1';
  391. $huiju = new HuijuH5Pay();
  392. $notify_url = 'http://'.$_SERVER['SERVER_NAME'].'/index.php/api/Pay/ylOrderNotify';//回调地址
  393. $pro_info = json_decode($order['pro_info'],true);
  394. $result = $huiju->ylh5Pay($order_nos,$callback_url,$notify_url,$pro_info['name'],$total_fee,$this->uid,1);
  395. if ($result['ra_Code']=='100'){
  396. $retrun_data['order_no'] = $order_nos;
  397. $retrun_data['pay'] = $result['rc_Result'];
  398. }else{
  399. $com = false;
  400. }
  401. break;
  402. case 'yhkj':
  403. $huiju = new HuijuKjPay();
  404. $result = $huiju->kuaijiePay($order_no,$sms_code);
  405. if ($result['resp_codo']=='SUCCESS'){
  406. if ($result['biz_code']=='JS000000'){
  407. $data = json_decode($result['data'],true);
  408. if ($data['order_status']=='P1000'){
  409. $this->success('支付成功');
  410. }else{
  411. $this->error($data['err_msg']);
  412. }
  413. }else{
  414. $this->error($result['biz_msg']);
  415. }
  416. }else{
  417. $this->error('支付失败');
  418. }
  419. break;
  420. }
  421. if ($com){
  422. $this->success('成功',$retrun_data);
  423. }else{
  424. $this->error('调起支付失败,请稍后重试');
  425. }
  426. }
  427. /**
  428. * @title 取消订单
  429. * @desc 取消订单
  430. * @author Gavin
  431. * @url /api/Order/cancelOrder
  432. * @method POST
  433. * @header name:Authorization require:1 desc:Token
  434. * @param name:order_no type:string require:1 default:-- desc:订单号
  435. */
  436. public function cancelOrder(){
  437. $order_no = input('order_no');
  438. if (!$order_no) $this->error('参数错误');
  439. $redis = new Redis();
  440. $key = 'order_not_pay_'.$this->uid;
  441. $order = $redis->hGet($key,$order_no);
  442. if (!$order) $this->error('订单不存在');
  443. $order = json_decode($order,true);
  444. if ($order['status']!=0) $this->error('订单已支付或已取消');
  445. $com = true;
  446. Db::startTrans();
  447. try {
  448. $order['status'] = 2;
  449. $order['cancel_at'] = date('Y-m-d H:i:s');
  450. $order['cancel_state'] = 2;
  451. Db::name('store_order')->insert($order);
  452. Db::commit();
  453. }catch (\Exception $e){
  454. $com=false;
  455. Db::rollback();
  456. }
  457. if ($com){
  458. //加上库存
  459. addCollectionInventory($order['c_id'],$order['num']);
  460. //减少用户购买数量
  461. DecrByCount($this->uid,$order['c_id'],$order['num']);
  462. //删除数据
  463. $redis->hdel($key,$order_no);
  464. $this->success('取消成功');
  465. }else{
  466. $this->error('取消失败,请稍后重试');
  467. }
  468. }
  469. /**
  470. * @title 我的订单-转赠
  471. * @desc 我的订单-转赠
  472. * @author Gavin
  473. * @url /api/Order/getMySendList
  474. * @method POST
  475. * @header name:Authorization require:1 desc:Token
  476. * @param name:page type:int : default:1 desc:页数
  477. * @param name:page_num type:int : default:20 desc:每页数
  478. *
  479. * @return name:order_no type:string default:-- desc:订单号
  480. * @return name:over_time type:string default:-- desc:转赠时间
  481. * @return name:status type:int default:-- desc:类型2:赠出3:获赠
  482. * @return name:send_name type:string default:-- desc:转赠者/受赠者
  483. * @return name:collectors_hash type:string default:-- desc:hash
  484. * @return name:pro_info@name type:string default:-- desc:藏品名称
  485. * @return name:pro_info@price type:string default:-- desc:藏品价格
  486. * @return name:pro_info@price type:string default:-- desc:藏品单价
  487. * @return name:pro_info@auth_img type:string default:-- desc:藏品作者头像
  488. * @return name:pro_info@auth_name type:string default:-- desc:藏品作者名称
  489. */
  490. public function getMySendList(){
  491. $where = [
  492. 'mid'=>$this->uid,
  493. ];
  494. $count = Db::name('store_order_info')->where($where)->whereIn('status','2,3')->count();
  495. $list = Db::name('store_order_info')
  496. ->where($where)
  497. ->whereIn('status','2,3')
  498. ->field('id,order_no,pro_info,over_time,create_at,status,to_mid,collectors_hash')
  499. ->order('id desc')
  500. ->limit($this->off_set,$this->page_num)
  501. ->select();
  502. foreach ($list as &$v){
  503. $v['pro_info'] = json_decode($v['pro_info'],true);
  504. $v['send_name'] = Db::name('store_member')->where('id',$v['to_mid'])->value('name');
  505. }
  506. $this->success('成功',compact('count','list'));
  507. }
  508. /**
  509. * @title 转赠订单详情
  510. * @desc 转赠订单详情
  511. * @author Gavin
  512. * @url /api/Order/getMySendListDetail
  513. * @method POST
  514. * @header name:Authorization require:1 desc:Token
  515. * @param name:order_id type:int : default:1 desc:订单ID
  516. *
  517. * @return name:order_no type:string default:-- desc:订单号
  518. * @return name:over_time type:string default:-- desc:转赠时间
  519. * @return name:status type:int default:-- desc:类型2:赠出3:获赠
  520. * @return name:send_name type:string default:-- desc:转赠者/受赠者
  521. * @return name:collectors_hash type:string default:-- desc:hash
  522. * @return name:pro_info@name type:string default:-- desc:藏品名称
  523. * @return name:pro_info@price type:string default:-- desc:藏品价格
  524. * @return name:pro_info@price type:string default:-- desc:藏品单价
  525. * @return name:pro_info@auth_img type:string default:-- desc:藏品作者头像
  526. * @return name:pro_info@auth_name type:string default:-- desc:藏品作者名称
  527. */
  528. public function getMySendListDetail(){
  529. $order_id = input('order_id'); //订单id
  530. if (!$order_id) $this->error('参数错误');
  531. $order = Db::name('store_order_info')
  532. ->where('id',$order_id)
  533. ->where('mid',$this->uid)
  534. ->find();
  535. if (!$order) $this->error('订单不存在');
  536. $order['pro_info'] = json_decode($order['pro_info'],true);
  537. $order['send_name'] = Db::name('store_member')->where('id',$order['to_mid'])->value('name');
  538. $this->success('成功',$order);
  539. }
  540. function savetest($order_no){
  541. $result['out_trade_no'] = $order_no;
  542. $order = Db::name('store_order')->where('order_no',$result['out_trade_no'])->find();
  543. if ($order['status']==0){
  544. Db::startTrans();
  545. try {
  546. Db::name('store_order')
  547. ->where('order_no',$result['out_trade_no'])
  548. ->update(['status'=>1,'pay_at'=>date('Y-m-d H:i:s'),'return_success_info'=>json_encode($result,true)]);
  549. $array = [];
  550. for ($i=0;$i<$order['num'];$i++){
  551. //获取排名
  552. $rank = getRanking($order['c_id'])+1;
  553. $tag = getTag($order['c_id'],$rank,$order['inventory']);
  554. saveRanking($order['c_id']);
  555. $company = '象寻数字科技(上海)有限公司';
  556. $company_hash = '';
  557. $company_hash_time = '';
  558. $collectors_hash = '';
  559. $date = [
  560. 'order_id'=>$order['id'],
  561. 'order_no'=>get_order_sn(),
  562. 'tag'=>$tag,
  563. 'mid'=>$order['mid'],
  564. 'pro_info'=>$order['pro_info'],
  565. 'company'=>$company,
  566. 'company_hash'=>$company_hash,
  567. 'company_hash_time'=>$company_hash_time,
  568. 'collectors_hash'=>$collectors_hash,
  569. 'collectors_hash_time'=>date('Y-m-d H:i:s')
  570. ];
  571. $array[] = $date;
  572. }
  573. Db::name('store_order_info')->insertAll($array);
  574. Db::commit();
  575. // return true;
  576. } catch (\Exception $e){
  577. Db::rollback();
  578. //return false;
  579. }
  580. }
  581. }
  582. }