Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

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