["code" => "后台补加余额", "content" => "后台补加余额:{money}。"], 'admin_cut' => ["code" => "后台补扣余额", "content" => "后台补扣余额:{money}。"], 'tx_apply' => ['code' => "提现余额", "content" => "您发起提现,扣除余额:{money}。"], 'tx_refund' => ['code' => "提现失败", "content" => "提现失败,返还余额:{money}。"], 'per_income' => ['code' => "商城购买分成", "content" => "{mono} ,商品购买分成获得:{money}。"], 'tree_per_income' => ['code' => "推广用户购买分成", "content" => "{mono} ,推广用户购买分成获得:{money}。"], ]; /** * 后台充值余额 * @param $uid * @param $money * @param $admin_id * @return bool * @throws \think\db\exception\DbException */ public function adminAddMoney($uid, $money,$admin_id,$othen="") { try { self::beginTrans(); $post['uid'] = $uid; $post['into'] = floatval($money); $post['code'] = 'admin_add'; $post['title'] = $this->config['admin_add']['code']; $post['content'] = $this->TplParam($this->config['admin_add']['content'],compact('money')); $post['type'] = 1; $post['money'] = (float)(new UserModel)->where('uid', $uid)->value('money') + floatval($money); $post['time'] = time(); $post['admin_id'] = $admin_id; $post['othen'] = $othen; $this->insert($post); $bool = Db::name("user")->where('uid', $uid)->inc('money', floatval($money))->update(); self::commitTrans(); if ($bool > 0) { return true; } else { return false; } } catch (DbException $db) { self::rollbackTrans(); return false; } } /** * 后台扣除余额 * @param $uid * @param $money * @param $admin_id * @return bool * @throws \think\db\exception\DbException */ public function adminCutMoney($uid, $money,$admin_id,$othen="") { try { self::beginTrans(); $post['uid'] = $uid; $post['into'] = floatval($money); $post['code'] = 'admin_cut'; $post['title'] = $this->config['admin_cut']['code']; $post['content'] = $this->TplParam($this->config['admin_cut']['content'],compact('money')); $post['type'] = -1; $post['money'] = (float)(new UserModel)->where('uid', $uid)->value('money') - floatval($money); $post['time'] = time(); $post['admin_id'] = $admin_id; $post['othen'] = $othen; $this->insert($post); $bool = Db::name("user")->where('uid', $uid)->dec('money', floatval($money))->update(); self::commitTrans(); if ($bool > 0) { return true; } else { return false; } } catch (DbException $db) { self::rollbackTrans(); return false; } } /** * 用户提现余额 * @param $uid * @param $money * @param $admin_id * @return bool * @throws \think\db\exception\DbException */ public function txApplyMoney($uid, $money,$tx_id) { $post['uid'] = $uid; $post['into'] = floatval($money); $post['code'] = 'tx_apply'; $post['title'] = $this->config['tx_apply']['code']; $post['content'] = $this->TplParam($this->config['tx_apply']['content'],compact('money')); $post['type'] = -1; $post['money'] = (float)(new UserModel)->where('uid', $uid)->value('money') - floatval($money); $post['time'] = time(); $post['tx_id'] = $tx_id; $this->insert($post); $bool = Db::name("user")->where('uid', $uid)->dec('money', floatval($money))->update(); if ($bool > 0) { return true; } else { return false; } } /** * 用户提现余额驳回返还 * @param $uid * @param $money * @param $admin_id * @return bool * @throws \think\db\exception\DbException */ public function txRefundMoney($uid, $money,$tx_id) { $post['uid'] = $uid; $post['into'] = floatval($money); $post['code'] = 'tx_refund'; $post['title'] = $this->config['tx_refund']['code']; $post['content'] = $this->TplParam($this->config['tx_refund']['content'],compact('money')); $post['type'] = 1; $post['money'] = (float)(new UserModel)->where('uid', $uid)->value('money') + floatval($money); $post['time'] = time(); $post['tx_id'] = $tx_id; $this->insert($post); $bool = Db::name("user")->where('uid', $uid)->inc('money', floatval($money))->update(); if ($bool > 0) { return true; } else { return false; } } /** * 购买获得收益 * @param type $uid * @param type $money * @param type $mono * @param type $parms */ public function goodsIncome($uid,$money,$code,$mono="",$parms=[]){ $money = num_min_format($money,2); $post['uid'] = $uid; $post['into'] = floatval($money); $post['code'] = $code; $post['title'] = $this->config[$code]['code']; $post['content'] = $this->TplParam($this->config[$code]['content'],compact('money','mono')); $post['type'] = 1;//收入为1,支出为-1 $post['money'] = (float)(new UserModel)->where('uid', $uid)->value('money') + floatval($money);//余额 $post['time'] = time(); $post['tx_id'] = 0; $post['cash_uid'] = empty($parms["cash_uid"]) ? 0 : $parms["cash_uid"]; $post['p_id'] = empty($parms["p_id"]) ? 0 : $parms["p_id"]; $post['o_id'] = empty($parms["o_id"]) ? 0 : $parms["o_id"]; $this->insert($post); //买断者收益 $perMoney = 0; if(in_array($code,["per_income"])){ $perMoney = floatval($money); } $bool = Db::name("user")->where('uid', $uid)->inc('money', floatval($money))->inc('money_in', $perMoney)->update(); if ($bool > 0) { return true; } else { return false; } } /** * 转义的模板信息 */ private function TplParam($content) { $data = func_get_args(); foreach ($data[1] as $k => $v) { $content = str_replace('{' . $k . '}', $v, $content); } return $content; } }