<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 合伙人申请好店订单表 Table<ai_allwin_user_worker_store_order>
 */
namespace app\allwin\model;

use think\Model;

class WorkerStoreOrder extends Model{

    protected $pk     = 'id';
    protected $table  = 'ai_allwin_user_worker_store_order';


    public static function createOrder(array $param){
        $info = self::where(['member_miniapp_id' => $param['member_miniapp_id'],'store_id' => $param['store_id']])->find();
        if($info){
            self::where(['id' => $info['id']])->update(['order_no' => $param['order_no'],'price' => $param['price'],'total_price' => $param['total_price']]);
            return false;
        }
        $data = [
            'uid'               => $param['uid'],
            'store_id'          => $param['store_id'],
            'is_type'           => 1,
            'price'             => $param['price'],
            'order_no'          => $param['order_no'],
            'total_price'       => $param['total_price'],
            'pay_state'         => $param['pay_state'],
            'create_time'       => time(),
            'member_miniapp_id' => $param['member_miniapp_id']
        ];
        $rel = self::insert($data);
        return $rel ? $info : false;
    }

}