* @version : HUOSDK 8.0 */ namespace huo\model\shop; use huo\model\common\CommonModel; use huolib\constant\MemItgConst; class ItgOrderModel extends CommonModel { protected $name = 'itg_order'; // 开启自动写入时间戳字段 protected $autoWriteTimestamp = true; /** * 关联商品 * * @return ItgOrderModel|\think\model\relation\BelongsTo */ public function goods() { return $this->hasOne('huo\model\shop\GoodsModel', 'id', 'goods_id', 'goods')->field( ['id', 'goods_name', 'object_type', 'is_real', 'original_img'] ); } /** * @return \think\model\relation\HasOne */ public function mem() { return $this->hasOne('huo\model\member\MemberModel', 'id', 'mem_id', 'mem')->field( ['id', 'username', 'nickname', 'avatar', 'mobile'] ); } /** * @return \think\model\relation\HasOne */ public function memMobile() { return $this->hasOne('huo\model\member\MemberModel', 'id', 'mem_id', 'mem')->field(['id', 'mobile']) ->setEagerlyType(0); } /** * 创建订单 * * @param array $data * * @return bool|array */ public function createOrder($data) { $_data['order_id'] = get_val($data, 'order_id', ''); $_data['mem_id'] = get_val($data, 'mem_id', 0); $_data['flag'] = get_val($data, 'flag', MemItgConst::SHOP_FLAG_UNKNOWN); $_data['act_id'] = get_val($data, 'act_id', MemItgConst::SHOP_FLAG_UNKNOWN); $_data['goods_id'] = get_val($data, 'goods_id', 0); $_data['integral'] = get_val($data, 'integral', 0.00); $_data['status'] = get_val($data, 'status', MemItgConst::PAY_STATUS_NOT); $_data['shipping_status'] = get_val($data, 'shipping_status', MemItgConst::SHIP_STATUS_NOT); $_data['consignee'] = get_val($data, 'consignee', ''); $_data['country'] = get_val($data, 'country', 0); $_data['province'] = get_val($data, 'province', 0); $_data['city'] = get_val($data, 'city', 0); $_data['district'] = get_val($data, 'district', 0); $_data['town'] = get_val($data, 'town', 0); $_data['address'] = get_val($data, 'address', ''); $_data['zipcode'] = get_val($data, 'zipcode', ''); $_data['mobile'] = get_val($data, 'mobile', ''); $_data['email'] = get_val($data, 'email', ''); $_data['shipping_code'] = get_val($data, 'shipping_code', ''); $_data['shipping_name'] = get_val($data, 'shipping_name', ''); $_data['shipping_price'] = get_val($data, 'shipping_price', 0.00); $_data['invoice_no'] = get_val($data, 'invoice_no', ''); $_data['user_note'] = get_val($data, 'user_note', ''); $_data['admin_note'] = get_val($data, 'admin_note', ''); $_data['shipping_time'] = get_val($data, 'shipping_time', 0); $_data['confirm_time'] = get_val($data, 'confirm_time', 0); if ($_obj = self::create($_data, true)) { $_data['id'] = $_obj->id; return $_data['id']; } else { return false; } } /** * 更新订单 * * @param array $order_data * @param string $io_id * * @return bool */ public function updateOrder($order_data, $io_id) { $_map['id'] = $io_id; $_data = $order_data; $_rs = self::update($_data, $_map, true); if (false == $_rs) { return false; } else { return true; } } /** * 获取订单状态 * * @param $order_id * * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getStatus($order_id) { $_map['order_id'] = $order_id; $_status = self::where($_map)->field('status, shipping_status')->find(); if (false == $_status) { return false; } $_rdata['status'] = $_status['status']; $_rdata['shipping_status'] = $_status['shipping_status']; return $_rdata; } /** * 获取订单详情 * * @param $order_id * * @return array|bool|false * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getDetail($order_id) { $_map['order_id'] = $order_id; $_data = self::with('goods')->where($_map)->find(); if (false == $_data) { return false; } if (is_object($_data)) { $_data = $_data->toArray(); } return $_data; } /** * 获取订单列表 * * @param $_map * @param $_order * @param $_offset * * @return \think\Paginator * @throws \think\exception\DbException */ public function getList($_map, $_order, $_offset) { $_field = 'id, order_id, mem_id, flag, goods_id, integral, status, shipping_status'; $_item = self::with('goods') ->with('mem') ->field($_field)->where($_map)->order($_order)->paginate($_offset); return $_item; } }