|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
-
- namespace app\api\controller;
-
- use addons\unishop\model\Order;
- use app\admin\model\unishop\OrderProduct;
- use app\admin\model\unishop\Product;
- use app\common\controller\Api;
-
- /**
- * 首页接口
- */
- class Index extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
-
- /**
- * 首页
- *
- */
- public function index()
- {
- $this->success('请求成功');
- }
-
- public function cancel(){
- $token = $this->request->request("token");
- if (md5("ikea")!=$token){
- return;
- }
- $model=new Order();
- $order = $model->field("GROUP_CONCAT(id) ids")->where([
- "createtime"=>["<",time()-1800],
- "have_paid"=>0,
- "status"=>1,
- ])->find();
- if (!$order){
- return;
- }
- $ids=explode(",",$order->ids);
- $orderProduct = new OrderProduct();
- $list =$orderProduct->where([
- 'order_id' => ["in",$ids],
- ])->select();
- $list = collection($list)->toArray();
- $product = new \app\admin\model\unishop\Product();
- foreach ($list as $val){
- $product->where(["id"=>$val['product_id']])->setInc("stock",$val["number"])->setInc("real_sales",-$val["number"]);
- }
- $model->save(["status"=>0],["id"=>["in",$ids]]);
- }
- }
|