审查视图

application/mobile/model/SecretOrder.php 1.7 KB
何书鹏 authored
1 2 3 4
<?php
namespace app\mobile\model;

use think\Model;
何书鹏 authored
5
use think\Db;
何书鹏 authored
6 7 8 9 10 11 12 13 14 15

class SecretOrder extends Model
{
	// 表名
    protected $name = 'mobile_secret_order';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
何书鹏 authored
16
何书鹏 authored
17 18 19 20 21
    // 密卷信息
    public function secret(){
    	return $this->belongsTo('Secret');
    }
何书鹏 authored
22 23 24 25 26 27
    /**
     * 新增订单
     */
    public function add($user, $order, $pay_type)
    {
        Db::startTrans();
何书鹏 authored
28 29 30 31 32 33 34 35
        $save_data = [
        	'user_id' => $user['id'],
            'secret_id' => $order['secret_info']['id'],
            'order_sn' => get_order_sn(),
            'pay_price' => $order['pay_price'],
            'pay_type' => $pay_type,
            'secret_price' => $order['secret_price']
        ];
何书鹏 authored
36 37
        // 记录订单信息
        if($user['group_id'] == 1){
何书鹏 authored
38 39
        	$this->save(array_merge([
                'company_id' => Company::where('user_id',$user['id'])->value('id'),
40 41 42
                'people_num' => $order['spec_info']['people_num'],
                'secret_spec_id' => $order['spec_info']['id'],
                'is_top' => $order['spec_info']['is_top'],
何书鹏 authored
43
            ],$save_data));
何书鹏 authored
44
        }else{
何书鹏 authored
45 46 47 48
        	$this->save(array_merge([
                'score' => $order['score_info']['use_score'],
                'score_price' => $order['score_info']['score_price'],
            ],$save_data));
何书鹏 authored
49 50 51 52 53 54 55 56
	        // 用掉积分
	        if($order['score_info']['use_score'] > 0){
	            \app\common\model\User::score(-$order['score_info']['use_score'],$user['id'],'密卷下单-使用积分');
	        }
        }
        Db::commit();
        return true;
    }
何书鹏 authored
57
}