* @version : HUOSDK 8.0 */ namespace huoAccountDeal\model; use huo\model\common\CommonModel; use huo\model\game\GameModel; use huo\model\member\MemberModel; use huo\model\member\MemGameModel; use huolib\constant\OrderConst; class AccountOrderModel extends CommonModel { protected $name = 'account_order'; // 开启自动写入时间戳字段 protected $autoWriteTimestamp = true; public function mg() { return $this->belongsTo(MemGameModel::className(), 'ags_id', 'id'); } public function game() { return $this->belongsTo(GameModel::className(), 'app_id', 'id'); } public function goods() { return $this->belongsTo(AccountGoodsModel::className(), 'ags_id', 'id'); } public function seller() { return $this->belongsTo(MemberModel::className(), 'sell_mem_id', 'id'); } public function buyer() { return $this->belongsTo(MemberModel::className(), 'buy_mem_id', 'id'); } public function addData($data) { if (empty($data)) { return false; } if ($_obj = self::create($data, true)) { return $_obj->id; } else { return false; } } public function updateData($_data, $am_id) { $_map['id'] = $am_id; $_rs = self::update($_data, $_map, true); if (false == $_rs) { return false; } else { return true; } } public function getSellCnt($mem_id) { return $this->where(['sell_mem_id' => $mem_id, 'status' => OrderConst::PAY_STATUS_SUC])->count(); } public function getBuyCnt($mem_id) { return $this->where(['buy_mem_id' => $mem_id, 'status' => OrderConst::PAY_STATUS_SUC])->count(); } public function getStatus($order_id) { $_map['order_id'] = $order_id; $_status = $this->where($_map)->value('status'); if (false == $_status) { return false; } $_rdata['status'] = $_status; return $_rdata; } public function getInfoByOrderId($order_id) { $_map['order_id'] = $order_id; $_info = $this->where($_map)->find(); if (false === $_info) { return false; } if (is_object($_info)) { return $_info->toArray(); } else { return $_info; } } /** * @param $order_id * * @return array|false */ public function getDetail($order_id) { $_map['order_id'] = $order_id; $_data = $this->where($_map)->find(); if (false == $_data) { return false; } if (is_object($_data)) { $_data = $_data->toArray(); } return $_data; } /** * @param array $data * @param string $id * * @return bool */ public function updateOrder($data, $id) { $_map['id'] = $id; $_data = $data; $_rs = self::update($_data, $_map, true); if (false == $_rs) { return false; } else { return true; } } }