tablePrefix ='tab_'; /* 执行构造方法 */ parent::__construct($name, $tablePrefix, $connection); } public function isLogin() { $user = session('promote_auth'); if (!empty($user)) { return $user; } return null; } /** * 更新时间 */ protected function getTime() { return date("Y-m-d H:i:s",time()); } /** * 转移平台币 * @param $uid 渠道ID * @param $sid 子渠道ID * @param $num 数量 */ public function shift_coin($uid,$sid,$num){ //扣除渠道平台币 $e_res2 = $this->edit_promote_balance_coin($uid,$num,2,$sid); //增加子渠道平台币 $e_res1 = $this->edit_promote_balance_coin($sid,$num,1,$uid); if($e_res2 && $e_res1){ return true; }else{ return false; } } public function shiftCoin($params){ //扣除渠道平台币 $e_res2 = $this->edit_promote_balance_coin($uid,$num,2,$sid); //增加子渠道平台币 $e_res1 = $this->edit_promote_balance_coin($sid,$num,1,$uid); if($e_res2 && $e_res1){ return true; }else{ return false; } } /** * 渠道平台币修改 * @param $promote_account 渠道帐号 * @param $num 平台币数量 * @param $type 1:增加 2:收回 */ public function edit_promote_balance_coin($promote_id,$num,$type,$sid=0){ //开启事务 $this->startTrans(); $map['id'] = $promote_id; $data = $this->where($map)->find(); if($type == 1){ $data['balance_coin'] += (int)$num; $res = $this->where($map)->save($data); } if($type == 2){ $data['balance_coin'] -= (int)$num; if($data['balance_coin'] < 0){ $data['balance_coin'] = 0; } $res = $this->where($map)->save($data); } $rec = D('PromoteCoin')->record($promote_id, $sid, $num, $type); if($res && $rec){ //事务提交 $this->commit(); }else{ //事务回滚 $this->rollback(); } return $res; } public function get_child_promote($pid,$field=true) { $map['parent_id'] = $pid; $map['grand_id'] = $pid; $map['_logic'] = 'or'; return $this->field($field)->where($map)->select(); } public function resetPassword($id, $password) { $password = $this->password($password, UC_AUTH_KEY); return $this->where("id=".$id)->save(['password' => $password]); } public function password($str, $key = 'ThinkUCenter') { return '' === $str ? '' : md5(sha1($str) . $key); } }