You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

58 line
1.5 KiB

  1. <?php
  2. namespace app\api\controller;
  3. use addons\unishop\model\Order;
  4. use app\admin\model\unishop\OrderProduct;
  5. use app\admin\model\unishop\Product;
  6. use app\common\controller\Api;
  7. use think\Exception;
  8. /**
  9. * 首页接口
  10. */
  11. class Index extends Api
  12. {
  13. protected $noNeedLogin = ['*'];
  14. protected $noNeedRight = ['*'];
  15. /**
  16. * 首页
  17. *
  18. */
  19. public function index()
  20. {
  21. $this->success('请求成功');
  22. }
  23. public function cancel(){
  24. $token = $this->request->request("token");
  25. if (md5("ikea")!=$token){
  26. return;
  27. }
  28. $model=new Order();
  29. $order = $model->field("GROUP_CONCAT(id) ids")->where([
  30. "createtime"=>["<",time()-1800],
  31. "have_paid"=>0,
  32. "status"=>1,
  33. ])->buildSql();
  34. if (!$order){
  35. return;
  36. }
  37. $ids=explode(",",$order->ids);
  38. $orderProduct = new OrderProduct();
  39. $list =$orderProduct->where([
  40. 'order_id' => ["in",$ids],
  41. ])->select();
  42. $list = collection($list)->toArray();
  43. $product = new \app\admin\model\unishop\Product();
  44. foreach ($list as $val){
  45. try {
  46. $product->where(["id"=>$val['product_id']])->setInc("stock",$val["number"]);
  47. $product->where(["id"=>$val['product_id']])->setInc("real_sales",-$val["number"]);
  48. }catch (Exception $e){}
  49. }
  50. $model->save(["status"=>0],["id"=>["in",$ids]]);
  51. }
  52. }