0) { $total = abs($this->app->db->name('DataUserBalance')->whereRaw("uid='{$uuid}' and amount>0 and deleted=0")->sum('amount')); $count = abs($this->app->db->name('DataUserBalance')->whereRaw("uid='{$uuid}' and amount<0 and deleted=0")->sum('amount')); if (empty($nots)) { $this->app->db->name('DataUser')->where(['id' => $uuid])->update(['balance_total' => $total, 'balance_used' => $count]); } else { $count -= $this->app->db->name('DataUserBalance')->whereRaw("uid={$uuid}")->whereIn('code', $nots)->sum('amount'); } } else { $total = abs($this->app->db->name('DataUserBalance')->whereRaw("amount>0 and deleted=0")->sum('amount')); $count = abs($this->app->db->name('DataUserBalance')->whereRaw("amount<0 and deleted=0")->sum('amount')); } return [$total, $count]; } /** * 验证订单发放余额 * @param string $orderNo * @return array [total, count] * @throws \think\admin\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function confirm(string $orderNo): array { $map = [['order_no', '=', $orderNo], ['status', '>=', 4]]; $order = $this->app->db->name('ShopOrder')->where($map)->find(); if (empty($order)) throw new \think\admin\Exception('需处理的订单状态异常'); data_save('DataUserBalance', [ 'uid' => $order['uid'], 'code' => $order['order_no'], 'name' => "订单余额充值", 'remark' => "来自订单{$order['order_no']}的余额充值", 'amount' => $order['reward_balance'], ], 'code'); return $this->amount($order['uid']); } }