user = $obj; } else { $this->store = $obj; } } //微信退款记录 /** * 用户收入 * @param $category * @param $linkType * @param $linkId * @param $amount * @param $mark * @return mixed */ public function userIncome($category, $linkType, $linkId, $amount, $mark = '', $type = 0) { $model = new CapitalFlow(); $model->uid = $this->user['id']; $model->category = $category; $model->link_type = $linkType; $model->link_id = $linkId; $model->amount = $amount; if ($type) { $model->before_balance = $this->user['purchase_funds']; $model->balance = bcadd($this->user['purchase_funds'], $amount, 2); } else { $model->before_balance = $this->user['now_money']; $model->balance = bcadd($this->user['now_money'], $amount, 2); } $model->create_time = date('Y-m-d H:i:s'); $model->type = 'in'; $model->title = $this->getTitle($category, $amount); $model->mark = empty($mark) ? $model->title : $mark; $model->save(); return $model->id; } /** * 用户支出 * @param $category * @param $store_id * @param $linkType * @param $linkId * @param $amount * @param $mark * @return mixed */ public function userExpense($category, $linkType, $linkId, $amount, $mark = '', $payType = 0, $store_id = 0) { $model = new CapitalFlow(); $model->uid = $this->user['id']; $model->category = $category; $model->store_id = $store_id; $model->link_type = $linkType; $model->link_id = $linkId; $model->amount = $amount; if ($payType == PayEnum::PURCHASE_FUNDS) { $model->before_balance = bcadd($this->user['purchase_funds'],$amount,2); $model->balance = $this->user['purchase_funds']; } elseif ($payType == PayEnum::BALANCE_PAY){ $model->before_balance = bcadd($this->user['now_money'],$amount,2); $model->balance = $this->user['now_money']; }else{ $model->before_balance = $this->user['now_money']; $model->balance = $this->user['now_money']; } $model->create_time = date('Y-m-d H:i:s'); $model->type = 'out'; $model->title = $this->getTitle($category, $amount); $model->mark = empty($mark) ? $model->title : $mark; $model->save(); return $model->id; } /** * 商户收入 * @param $category * @param $linkType * @param $linkId * @param $amount * @param $mark * @return mixed */ public function storeIncome($category, $linkType, $linkId, $amount, $mark = '') { $model = new CapitalFlow(); $model->store_id = $this->store['id']; $model->category = $category; $model->link_type = $linkType; $model->link_id = $linkId; $model->amount = $amount; $model->before_balance = $this->store['balance']; $model->balance = bcadd($this->store['balance'], $amount, 2); $model->create_time = date('Y-m-d H:i:s'); $model->type = 'in'; $model->title = $this->getTitle($category, $amount); $model->mark = empty($mark) ? $model->title : $mark; $model->save(); $this->store->update(['balance' => $model->balance], ['id' => $this->store['id']]); return $model->id; } /** * 商户支出 * @param $category * @param $linkType * @param $linkId * @param $amount * @param $mark * @return mixed */ public function storeExpense($category, $linkType, $linkId, $amount, $mark = '') { $model = new CapitalFlow(); $model->store_id = $this->store['store_id']; $model->uid = 0; $model->category = $category; $model->link_type = $linkType; $model->link_id = $linkId; $model->amount = $amount; $model->before_balance = $this->store['balance']; $model->balance = bcsub($this->store['balance'], $amount, 2); $model->create_time = date('Y-m-d H:i:s'); $model->type = 'out'; $model->title = $this->getTitle($category, $amount); $model->mark = empty($mark) ? $model->title : $mark; $model->save(); $this->store->update(['balance' => $model->balance], ['id' => $this->store['id']]); return $model->id; } public function getTitle($category, $amount) { switch ($category) { case 'user_balance_recharge': return "用户增加{$amount}元"; case 'user_order_purchase_pay': return "用户采购款支付{$amount}元"; case 'store_margin': return "店铺自动扣除保证金{$amount}元"; case 'store_order_income': return "店铺订单收入{$amount}元"; case 'user_order_refund': return "用户订单退款{$amount}元"; case 'store_order_refund': return "店铺订单退款{$amount}元"; case 'store_margin_refund': return "店铺退还保证金{$amount}元"; case 'user_order_promotion': return "订单推广佣金{$amount}元"; case 'user_order_promotion_refund': return "退还订单推广佣金{$amount}元"; case 'system_balance_add': return "系统增加余额{$amount}元"; case 'system_purchase_add': return "系统增加采购款{$amount}元"; case 'system_balance_reduce': return "系统减少余额{$amount}元"; case 'user_balance_recharge_refund': return "用户减少{$amount}元"; default: return "订单支付{$amount}元"; } } }