| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 | <?php/** * PayAppleModel.php UTF-8 * 苹果支付记录表 * * @date    : 2018/6/11 15:37 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : wuyonghong <wyh@huosdk.com> * @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;    }}
 |