postForm(); $post['code'] = rand(10000000,99999999); if (isset($post['role']) && $post['role'] == 1) { $post['audit_time'] = Date("Y-m-d H:i:s", time()); $post['audit_status'] = 1; } else { $post['audit_status'] = 0; } if ($model->addOne($post)&&$model->getError()=='') { return $this->renderSuccess('添加成功'); } return $this->renderError($model->getError() ?: '添加失败'); } /** * 列表 * @return array * @throws \think\db\exception\DbException */ public function list() { $model = new ZaActiivtyModel; $list = $model->getList($this->request->param()); return $this->renderSuccess(compact('list')); } /** * 审核 * @param int $coupon_id * @return array|bool */ public function audit() { // 确认审核 $postData = $this->postForm(); $model = ZaActiivtyModel::where('id',$postData['id'])->find(); if(empty($model)){ return $this->renderError('找不到数据'); } unset($postData['id']); $res ='操作成功'; $audit_status = $postData['audit_status']; if($audit_status==1){ $res = '已审核通过'; } if($audit_status==2){ $res = '已审核不通过'; } $postData['audit_time'] = Date("Y-m-d H:i:s",time()); $postData['admin_id'] = $this->store['user']['store_user_id']; if ($model->audit($postData)) { return $this->renderSuccess($postData,$res); } return $this->renderError($model->getError() ?: '操作失败'); } /** * 详情 */ public function activityinfo(int $id){ $data = ZaActiivtyModel::where('id',$id)->with(['goodsInfos','his'])->find(); foreach($data['goodsInfos'] as &$r){ $good = Goods::where('goods_id',$r['goods_id'])->find(); $r['goods_status'] = $good->status??20; $r['stock_total'] = $good->stock_total??0; } if(empty($data)){ return $this->renderError("找不到信息"); } return $this->renderSuccess(compact("data")); } /** * 启用 禁用 * @param int $coupon_id * @return array|bool */ public function down(int $id){ // 确认审核 // $postData = $this->postForm(); $model = ZaActiivtyModel::where('id',$id)->find(); if(empty($model)){ return $this->renderError('找不到数据'); } if($model['is_up']==0){ return $this->renderError('已经作废了,不要重复操作'); } $postData['is_up'] = 0; $postData['end_time'] = Date("Y-m-d H:i:s",time()-1); if ($model->down($postData)) { return $this->renderSuccess($postData,'作废成功,活动已失效'); } return $this->renderError($model->getError() ?: '操作失败'); } public function edit(){ // 新增记录 $model = new ZaActiivtyModel; $post = $this->postForm(); $post['audit_status'] = 0; $model = ZaActiivtyModel::where('id',$post['id'])->find(); if ($model->edit($post)&&$model->getError()=='') { return $this->renderSuccess('修改成功'); } return $this->renderError($model->getError() ?: '添加失败'); } /** * 活动商品数据 */ public function activityGoods(int $id){ $goods = []; $data = ZaActiivtyModel::where('id',$id)->with(['goodsInfos'])->find(); foreach($data['goodsInfos'] as &$r){ $good = Goods::field(['goods_id, goods_name', 'goods_no', 'goods_price_min']) ->where('goods_id',$r['goods_id'])->find(); array_push($goods, $good); // $r['goods_status'] = $good->status??20; // $r['stock_total'] = $good->stock_total??0; } if(empty($data)){ return $this->renderError("找不到信息"); } return $this->renderSuccess(compact("goods")); } public function orderSt(int $id) { $data = []; // 查询订单数 $orderCount = ZaActivityRelationModel::where('za_activity_id', $id) ->count(); $data['order_count'] = $orderCount; // 查询下单人数 $payCount = ZaActivityRelationModel::where('za_activity_id', $id) ->where('is_pay', "=", "1")->count(); $data['pay_count'] = $payCount; // 查询领取人数 $getCount = ZaActivityRelationModel::where('za_activity_id', $id) ->where('is_pay', "=", "1") ->where('receive_state', "=", "1")->count(); $data['get_count'] = $getCount; $payTotal = ZaActivityRelationModel::alias('zrm') ->field('sum(g.goods_price) total_price') ->leftjoin('za_activity_goods g', 'g.za_activity_id=zrm.za_activity_id and g.id=zrm.za_goods_id') ->where('zrm.za_activity_id', $id) ->where('is_pay', "=", "1") ->find() ; $data['total_price'] = $payTotal['total_price']; // number_format($total_price, 2); return $this->renderSuccess(compact("data")); } public function orderList() { $param = $this->request->param(); $list = ZaActivityRelationModel::alias('zrm') ->field(['zrm.id', 'user.nick_name', 'getu.nick_name as g_nick_name', 'zrm.order_id', 'zrm.child_order_id', 'zrm.receive_state', 'zrm.create_time', 'zrm.is_pay', 'zrm.order_price' ]) ->leftjoin('za_activity_goods zzg','zzg.za_activity_id=zrm.za_activity_id and zzg.id=zrm.za_goods_id') ->leftjoin('order','order.order_id = zrm.order_id') ->leftjoin('user','user.user_id=order.user_id') ->leftjoin('user getu','getu.user_id=zrm.receive_user_id') ->where('zrm.za_activity_id', $param['id']) ->order('create_time desc') ->paginate(15) ; return $this->renderSuccess(compact("list")); } } ?>