From 4b23d07cc7f6e93024cdeaf72ff351e3d4675e6a Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 29 Aug 2023 11:55:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/model/AwardsRecords.php | 34 ++++++++++++++++++++++ app/model/ConsumptionRecords.php | 49 ++++++++++++++++++++++++++++++++ app/model/User.php | 34 ++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 app/model/AwardsRecords.php create mode 100644 app/model/ConsumptionRecords.php diff --git a/app/model/AwardsRecords.php b/app/model/AwardsRecords.php new file mode 100644 index 0000000..35b0cdf --- /dev/null +++ b/app/model/AwardsRecords.php @@ -0,0 +1,34 @@ +user_id = $user_id; + $records->cr_id = $cr_id; + $records->awards_amount = $amount; + $records->withdrawal_balance= $balance; + $records->create_time = date("Y-m-d H:i:s",time()); + $records->save(); + + return $records->id; + } + +} \ No newline at end of file diff --git a/app/model/ConsumptionRecords.php b/app/model/ConsumptionRecords.php new file mode 100644 index 0000000..0db470f --- /dev/null +++ b/app/model/ConsumptionRecords.php @@ -0,0 +1,49 @@ +user_id = $user_id; + $records->zone_goods_id = $z_g_id; + $records->price = $price; + $records->text_data = serialize($data); + $records->actual_price = $actual_price; + $records->residue_amount = $residue_amount; + $records->create_time = date("Y-m-d H:i:s",time()); + $records->save(); + return $records->id; + } + + /** + * 完成订单 + * @param $zone_goods_id + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function endOrder($c_r_id) + { + + $zoneOrder = ConsumptionRecords::find($c_r_id); + $zoneOrder->status = 1; + $zoneOrder->complete_time = date("Y-m-d H:i:s",time()); + $zoneOrder->save(); + } + +} \ No newline at end of file diff --git a/app/model/User.php b/app/model/User.php index 01fb4c7..b848744 100644 --- a/app/model/User.php +++ b/app/model/User.php @@ -186,6 +186,40 @@ class User extends Model return true; } + /** + * 扣减余额 + * @param $user_id + * @param $balance + * @return float|mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function decrBalance($user_id,$balance) + { + $user = self::find($user_id); + $user->balance = round($user->balance + $balance,2); + $user->save(); + return $user->balance; + } + + /** + * 增加余额 + * @param $user_id + * @param $balance + * @return float|mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function IncrBalance($user_id,$balance) + { + $user = self::find($user_id); + $user->balance = round($user->balance - $balance,2); + $user->save(); + return $user->balance; + } + /** * 生成盐值 * @return string