* @version : HUOSDK 8.0 */ namespace huo\model\order; use huo\model\common\CommonModel; use huo\model\member\MemberModel; use huolib\constant\CommonConst; class PayAppleModel extends CommonModel { protected $name = 'pay_apple'; // 开启自动写入时间戳字段 protected $autoWriteTimestamp = true; public function mem() { return $this->belongsTo(MemberModel::className(), 'mem_id', 'id'); } public function pay() { return $this->belongsTo(OrderModel::className(), 'order_id', 'order_id'); } /** * @param array $data * * @return bool|array */ public function addData($data) { $_data['order_id'] = get_val($data, 'order_id', ''); $_data['mem_id'] = get_val($data, 'mem_id', 0); $_data['mg_mem_id'] = get_val($data, 'mg_mem_id', 0); $_data['apple_id'] = get_val($data, 'apple_id', ''); $_data['product_id'] = get_val($data, 'product_id', ''); $_data['idfv'] = get_val($data, 'idfv', ''); $_data['idfa'] = get_val($data, 'idfa', ''); if ($_obj = self::create($_data, true)) { $_data['id'] = $_obj->id; return $_data; } else { return false; } } /** * @param array $data * @param int $id * * @return bool */ public function updateData($data, $id) { $_map['id'] = $id; $_data = $data; $_rs = self::update($_data, $_map, true); if (false == $_rs) { return false; } else { return true; } } /** * @param string $trans_id 苹果订单号 * * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getStatusByTransId($trans_id) { if (empty($trans_id)) { return false; } $_map['trans_id'] = $trans_id; $_status = self::where($_map)->field('cp_status, status')->find(); if (false == $_status) { return false; } $_rdata['status'] = $_status['status']; $_rdata['cp_status'] = $_status['cp_status']; return $_rdata; } /** * 通过苹果订单号获取详情 * * @param string $trans_id 苹果订单号 * * @return array|false * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getInfoByTransId($trans_id) { if (empty($trans_id)) { return false; } $_map['trans_id'] = $trans_id; $_data = self::where($_map)->find(); if (false == $_data) { return false; } $_data = $_data->toArray(); return $_data; } /** * 通过订单号获取详情 * * @param string $order_id 平台订单号 * * @return array|false * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getInfoByOrderId($order_id) { if (empty($order_id)) { return false; } $_map['order_id'] = $order_id; $_data = self::where($_map)->find(); if (false == $_data) { return false; } $_data = $_data->toArray(); return $_data; } /** * 获取最近订单信息 * * @param string $end_time 结束时间 * @param string $idfv IDFV * @param string $apple_id 苹果ID * @param string $product_id 商品ID * * @return array|false * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getLastOrderData($end_time, $idfv, $apple_id, $product_id) { /* 3 天以内最近的订单 */ $_end_time = $end_time; $_start_time = $_end_time - 3 * CommonConst::CONST_DAY_SECONDS; $_map['create_time'] = ['between', [$_start_time, $_end_time]]; $_map['idfv'] = $idfv; $_map['apple_id'] = $apple_id; $_map['product_id'] = $product_id; $_map['trans_id'] = ['neq', '']; $_data = self::where($_map)->order('id desc')->find(); if (false == $_data) { return false; } $_data = $_data->toArray(); return $_data; } }