SellerInputRecord.php 4.01 KB
<?php

namespace domain\user;

use Yii;
use domain\user\models\SellerInputRecord as SellerInputRecordModel;
use Exception;

/**

 * Class SellerInputRecord
 * @package domain\user
 */
class SellerInputRecord
{
    /**
     * 创建激活记录
     * @param $item
     */
    static function create($item)
    {
        try {
            $sellerInputRecordModel = Yii::createObject(SellerInputRecordModel::className());
            $sellerInputRecordModel->user_mp_id = trim($item["user_mp_id"]); // 用户编号
            $sellerInputRecordModel->leave_message = trim($item['leave_message']); // 商家留言
            $sellerInputRecordModel->delivery_address = trim($item['delivery_address']); // 发货地址
            $sellerInputRecordModel->product_image_path = trim($item['product_image_path']); // 商品图片
            $sellerInputRecordModel->product_vedio_path = trim($item['product_vedio_path']); // 商品视频
            $sellerInputRecordModel->buyer_mobile = trim($item['buyer_mobile']); // 买家手机号
            $sellerInputRecordModel->uuid = trim($item['uuid']); // 验证编号
            $sellerInputRecordModel->extraction_code = trim($item['extraction_code']); // 提取码
            $result = $sellerInputRecordModel->save();

            if($result) {
                // 新增用户地址
                if (trim($item['delivery_address'])) {
                    $userAddress = UserAddress::create([
                        "user_id" => trim($item["user_mp_id"]),
                        "address" => trim($item['delivery_address']),
                    ]);
                }
                $result = $sellerInputRecordModel->id;
            } else {
                $result = false;
            }
            return $result;
        } catch (Exception $e) {
            return false;
        }
    }

    /**
     * @param $id
     * @param $item
     * @return null|static
     */
    static function update($id, $item)
    {
        $sellerInputRecordModel = SellerInputRecordModel::findOne($id);
        if (empty($sellerInputRecordModel)) {
            return false;
        }

        if (isset($item['user_mp_id']) && !empty($item['user_mp_id'])) {
            $sellerInputRecordModel->user_mp_id = trim($item["user_mp_id"]); // user_mp_id
        }
        if (isset($item['leave_message']) && !empty($item['leave_message'])) {
            $sellerInputRecordModel->leave_message = trim($item['leave_message']); // leave_message
        }
        if (isset($item['delivery_address']) && !empty($item['delivery_address'])) {
            $sellerInputRecordModel->delivery_address = trim($item['delivery_address']); // 发货地址
        }
        if (isset($item['product_image_path']) && !empty($item['product_image_path'])) {
            $sellerInputRecordModel->product_image_path = trim($item['product_image_path']); // 商品图片
        }
        if (isset($item['product_vedio_path']) && !empty($item['product_vedio_path'])) {
            $sellerInputRecordModel->product_vedio_path = trim($item['product_vedio_path']); // 产品视频
        }
        if (isset($item['buyer_mobile']) && !empty($item['buyer_mobile'])) {
            $sellerInputRecordModel->buyer_mobile = trim($item['buyer_mobile']); // 买家手机号
        }
        if (isset($item['extraction_code']) && !empty($item['extraction_code'])) {
            $sellerInputRecordModel->extraction_code = trim($item['extraction_code']); // 提取码
        }
        if (isset($item['uuid']) && !empty($item['uuid'])) {
            $sellerInputRecordModel->uuid = trim($item['uuid']); // 激活编号
        }

        $resultSave = $sellerInputRecordModel->save();

        return $resultSave;
    }

    /**
     * @param $id
     * @param $item
     * @return null|static
     */
    public static function delete($id)
    {
        $sellerInputRecordModel = SellerInputRecordModel::findOne($id);
        if (empty($sellerInputRecordModel)) {
            return false;
        }

        return SellerInputRecordModel::updateAll(["is_delete" => 1], ["id" => $id]);
    }
}