From 6c7023a25c3f8b0f4ae4d0879b9712a9361b7334 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Fri, 1 Sep 2023 09:59:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=AE=E5=A5=96=E7=BB=93=E6=9D=9F=EF=BC=8C?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E4=B8=AD=E5=A5=96=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/Zone.php | 5 ++--- app/logic/Zone.php | 17 +++++++++++------ app/model/ConsumptionRecords.php | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/controller/Zone.php b/app/controller/Zone.php index 1e12c37..ebacbcf 100644 --- a/app/controller/Zone.php +++ b/app/controller/Zone.php @@ -61,8 +61,7 @@ class Zone extends BaseController /** * 结束刮奖 - * @param $c_r_id - * @return array|void + * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException @@ -79,7 +78,7 @@ class Zone extends BaseController return $this->renderSuccess( $res['awards_amount'] > 0 ? '恭喜你中奖了' : '未中奖', - ['awards_amount' => $res['awards_amount']] + ['awards_amount' => $res['awards_amount'],'list' => $res['data']] ); } diff --git a/app/logic/Zone.php b/app/logic/Zone.php index 73de7de..c0ca5be 100644 --- a/app/logic/Zone.php +++ b/app/logic/Zone.php @@ -86,23 +86,28 @@ class Zone # 验证 $queryWhere = ['status' => 0, 'user_id' => $user_id, 'id' => $c_r_id]; - $zoneOrderModel = new ConsumptionRecords(); - $query = $zoneOrderModel->where($queryWhere)->field('text_data,zone_goods_id')->find(); + $ConsumptionRecords = new ConsumptionRecords(); + $query = $ConsumptionRecords->where($queryWhere)->field('text_data,zone_goods_id')->find(); if (!$query) return ['status' => 0, 'msg' => '刮奖结果已公布']; # 解密 $data = unserialize($query['text_data']); - + $returnData = []; # 解析是否中奖 $awards_amount = 0; - foreach ($data as $goodsParam) { - foreach ($goodsParam as $item) { + foreach ($data as $key => $goodsParam) { + foreach ($goodsParam as $k => $item) { + $data[$key][$k]['is_awards'] = 0; $awardsAmountRes = ZoneGoodsParam::getAwardsAmount($item['id']); if ($awardsAmountRes) { + $data[$key][$k]['is_awards'] = 1; $awards_amount += $item['amount']; } + $returnData[$key][$k] = $data[$key][$k]; + unset($returnData[$key][$k]['id']); } } + $ConsumptionRecords->awardsData($data,$c_r_id); # 开启事务 $connection = Db::connect(); @@ -123,7 +128,7 @@ class Zone ConsumptionRecords::endOrder($c_r_id,$awards_amount); $connection->commit(); - return ['status' => 1, 'msg' => '完成', 'awards_amount' => $awards_amount]; + return ['status' => 1, 'msg' => '完成', 'awards_amount' => $awards_amount, 'data' => $returnData]; } catch (\Exception $e) { $connection->rollback(); diff --git a/app/model/ConsumptionRecords.php b/app/model/ConsumptionRecords.php index 87b6f80..479f999 100644 --- a/app/model/ConsumptionRecords.php +++ b/app/model/ConsumptionRecords.php @@ -50,4 +50,19 @@ class ConsumptionRecords extends Model $zoneOrder->save(); } + /** + * 保存是否中奖字段 + * @param $data + * @param $id + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function awardsData($data,$id) + { + $ConsumptionRecords = ConsumptionRecords::find($id); + $ConsumptionRecords->text_data = serialize($data); + $ConsumptionRecords->save(); + } + } \ No newline at end of file