| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace app\business;
- use Illuminate\Support\Arr;
- use support\Db;
- use support\Redis;
- class StreamBusiness
- {
- /** 新增金额
- * @param $uid
- * @param $money
- * @param $type
- * @param $mold
- * @param $mold_filed
- * @param $source_id
- * @return void
- * @throws \Exception
- */
- static public function addStream($uid, $money, $type, $mold, $mold_filed, $source_id = 0)
- {
- try {
- $userData = Db::table('wa_users')->where('id', $uid)->first();
- Db::table('wa_users')->where('id', $uid)->increment($mold_filed, $money);
- $total_money = bcadd($userData->$mold_filed, $money, 2);
- Db::table('wa_stream')->insert([
- 'user_id' => $uid,
- 'money' => $money,
- 'total_money' => $total_money,
- 'type' => $type,
- 'mold' => $mold,
- 'source_id' => $source_id,
- 'add_time' => time(),
- 'created_at' => date('Y-m-d H:i:s'),
- 'updated_at' => date('Y-m-d H:i:s'),
- ]);
- } catch (\Throwable $exception) {
- throw new \Exception($exception->getMessage());
- }
- }
- /** 扣除金额
- * @param $uid
- * @param $money
- * @param $type
- * @param $mold
- * @param $mold_filed
- * @param $source_id
- * @return void
- * @throws \Exception
- */
- static public function delStream($uid, $money, $type, $mold, $mold_filed, $source_id = 0)
- {
- try {
- $userData = Db::table('wa_users')->where('id', $uid)->first();
- Db::table('wa_users')->where('id', $uid)->decrement($mold_filed, $money);
- $total_money = bcsub($userData->$mold_filed, $money, 2);
- if ($total_money < 0) {
- throw new \Exception('您余额不足!');
- }
- Db::table('wa_stream')->insert([
- 'user_id' => $uid,
- 'money' => '-' . $money,
- 'consume_money' => $money,
- 'total_money' => $total_money,
- 'income' => 2,
- 'type' => $type,
- 'mold' => $mold,
- 'source_id' => $source_id,
- 'add_time' => time(),
- 'created_at' => date('Y-m-d H:i:s'),
- 'updated_at' => date('Y-m-d H:i:s'),
- ]);
- } catch (\Throwable $exception) {
- throw new \Exception($exception->getMessage());
- }
- }
- }
|