<commit_before><?php
namespace app\models;

/*
DROP TABLE IF EXISTS wx_order;
CREATE TABLE wx_order (
    oid VARCHAR(32) NOT NULL DEFAULT '',
    gh_id VARCHAR(32) NOT NULL DEFAULT '',
    openid VARCHAR(32) NOT NULL DEFAULT '',
    scene_id int(10) unsigned NOT NULL DEFAULT '0',    
    scene_src_id int(10) unsigned NOT NULL DEFAULT '0',    
    scene_amt int(10) NOT NULL DEFAULT '0',
    iid int(10) unsigned NOT NULL DEFAULT '0',
    feesum int(10) unsigned NOT NULL DEFAULT '0',
    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,    
    status int(10) unsigned NOT NULL DEFAULT '0',
    title VARCHAR(128) NOT NULL DEFAULT '',    
    select_mobnum VARCHAR(16) NOT NULL DEFAULT '',        
    attr VARCHAR(256) NOT NULL DEFAULT '',
    office_id int(10) unsigned NOT NULL DEFAULT '0',
    detail VARCHAR(512) NOT NULL DEFAULT '',
    cid int(10) unsigned NOT NULL DEFAULT '0',
    notify_id VARCHAR(256) NOT NULL DEFAULT '',
    partner VARCHAR(32) NOT NULL DEFAULT '',
    time_end VARCHAR(16) NOT NULL DEFAULT '',    
    total_fee int(10) unsigned NOT NULL DEFAULT '0',
    trade_state int(10) unsigned NOT NULL DEFAULT '0',    
    transaction_id VARCHAR(32) NOT NULL DEFAULT '',    
    appid_recv VARCHAR(64) NOT NULL DEFAULT '',
    openid_recv VARCHAR(32) NOT NULL DEFAULT '',    
    issubscribe_recv tinyint(1) unsigned NOT NULL DEFAULT '0',
    userid VARCHAR(32) NOT NULL DEFAULT '',
    username VARCHAR(16) NOT NULL DEFAULT '',
    usermobile VARCHAR(16) NOT NULL DEFAULT '',   
    address VARCHAR(256) NOT NULL DEFAULT '',
    kaitong VARCHAR(16) NOT NULL DEFAULT '',
    pay_kind tinyint(10) unsigned NOT NULL DEFAULT '0',
    aliwap_trade_no VARCHAR(64) NOT NULL DEFAULT '',
    aliwap_total_fee VARCHAR(16) NOT NULL DEFAULT '',
    aliwap_trade_status VARCHAR(32) NOT NULL DEFAULT '',
    aliwap_buyer_email VARCHAR(64) NOT NULL DEFAULT '',
    aliwap_quantity int(10) unsigned NOT NULL DEFAULT '0',
    aliwap_gmt_payment TIMESTAMP,
    memo VARCHAR(256) NOT NULL DEFAULT '',
    val_pkg_3g4g VARCHAR(32) NOT NULL DEFAULT '',
    val_pkg_period int(10) unsigned NOT NULL DEFAULT '0',
    val_pkg_monthprice int(10) unsigned NOT NULL DEFAULT '0',
    val_pkg_plan VARCHAR(8) NOT NULL DEFAULT '',
    PRIMARY KEY (oid),
    KEY gh_id_oid(gh_id,oid),
    KEY gh_id_office_id(gh_id,office_id),
    KEY gh_id_aliwap_trade_no(gh_id,aliwap_trade_no),    
    KEY gh_id_idx(gh_id,openid)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


ALTER TABLE wx_order ADD scene_amt int(10) NOT NULL DEFAULT '0' after openid;
ALTER TABLE wx_order ADD scene_src_id int(10) unsigned NOT NULL DEFAULT '0' after openid;
ALTER TABLE wx_order ADD scene_id int(10) unsigned NOT NULL DEFAULT '0' after openid;

*/

use Yii;
use yii\db\ActiveRecord;
use yii\helpers\Security;
use yii\web\IdentityInterface;
use yii\behaviors\TimestampBehavior;
use app\models\U;
use app\models\MUser;
use app\models\MItem;
use app\models\MOffice;
use app\models\MSceneDetail;

class MOrder extends ActiveRecord
{
    const STATUS_AUTION = 0;
    const STATUS_OK = 3;        
    const STATUS_CLOSED_USER = 7;        
    const STATUS_CLOSED_AUTO = 9;            

    const PAY_KIND_CASH = 0;
    const PAY_KIND_ALIWAP = 1;
    const PAY_KIND_WECHAT = 2;

    const NO_CHOICE = 'null';
    
    public function attributeLabels()
    {
        return [
            'oid' => '订单号',
            'nickname' => '用户昵称',
            'title' => '商品名称',
            'cid' => '商品类别',
            'detail' => '商品详情',
            'feesum' => '支付金额',
            'status' => '订单状态',
            'select_mobnum'=>'手机号码',
            'create_time' => '创建时间',
            'userid' => '身份证',
            'username' => '姓名',
            'usermobile' => '联系电话',
            'address' => '收货地址',
            'kaitong' => '开通',
            'office_id' => '营业厅编号',
            'pay_kind' => '付款方式',
            'memo' => '留言',
        ];
    }

    public function rules()
    {
        return [
            [['status', 'pay_kind'], 'integer'],                    
            [['select_mobnum'],  'string', 'min' => 11, 'max' => 11],
            [['select_mobnum'],  'number'],  
            [['address'],  'string', 'min' => 5, 'max' => 256], 
            [['kaitong'],  'string', 'min' => 1, 'max' => 16],      
        ];
    }

    public function afterSave($insert, $changedAttributes)
    {        
        if (!empty($this->scene_id) && !empty($this->scene_amt))
        {
            if ($insert)
            {
                $ar = new MSceneDetail;
                $ar->scene_id = $this->scene_id;             
                $ar->scene_src_id = $this->scene_src_id;
                $ar->gh_id = $this->gh_id;
                $ar->openid = $this->openid;
                $ar->amount = $this->scene_amt;
                $ar->oid = $this->oid;
                $ar->memo = $this->detail;                 
            }
            else
            {
            }
            $ar->status = $this->status == MOrder::STATUS_OK ? MSceneDetail::STATUS_CONFIRMED : MSceneDetail::STATUS_AUCTION;
            $ar->save(false);<commit_msg>add<commit_after><?php
namespace app\models;

/*
DROP TABLE IF EXISTS wx_order;
CREATE TABLE wx_order (
    oid VARCHAR(32) NOT NULL DEFAULT '',
    gh_id VARCHAR(32) NOT NULL DEFAULT '',
    openid VARCHAR(32) NOT NULL DEFAULT '',
    scene_id int(10) unsigned NOT NULL DEFAULT '0',    
    scene_src_id int(10) unsigned NOT NULL DEFAULT '0',    
    scene_amt int(10) NOT NULL DEFAULT '0',
    iid int(10) unsigned NOT NULL DEFAULT '0',
    feesum int(10) unsigned NOT NULL DEFAULT '0',
    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,    
    status int(10) unsigned NOT NULL DEFAULT '0',
    title VARCHAR(128) NOT NULL DEFAULT '',    
    select_mobnum VARCHAR(16) NOT NULL DEFAULT '',        
    attr VARCHAR(256) NOT NULL DEFAULT '',
    office_id int(10) unsigned NOT NULL DEFAULT '0',
    detail VARCHAR(512) NOT NULL DEFAULT '',
    cid int(10) unsigned NOT NULL DEFAULT '0',
    notify_id VARCHAR(256) NOT NULL DEFAULT '',
    partner VARCHAR(32) NOT NULL DEFAULT '',
    time_end VARCHAR(16) NOT NULL DEFAULT '',    
    total_fee int(10) unsigned NOT NULL DEFAULT '0',
    trade_state int(10) unsigned NOT NULL DEFAULT '0',    
    transaction_id VARCHAR(32) NOT NULL DEFAULT '',    
    appid_recv VARCHAR(64) NOT NULL DEFAULT '',
    openid_recv VARCHAR(32) NOT NULL DEFAULT '',    
    issubscribe_recv tinyint(1) unsigned NOT NULL DEFAULT '0',
    userid VARCHAR(32) NOT NULL DEFAULT '',
    username VARCHAR(16) NOT NULL DEFAULT '',
    usermobile VARCHAR(16) NOT NULL DEFAULT '',   
    address VARCHAR(256) NOT NULL DEFAULT '',
    kaitong VARCHAR(16) NOT NULL DEFAULT '',
    pay_kind tinyint(10) unsigned NOT NULL DEFAULT '0',
    aliwap_trade_no VARCHAR(64) NOT NULL DEFAULT '',
    aliwap_total_fee VARCHAR(16) NOT NULL DEFAULT '',
    aliwap_trade_status VARCHAR(32) NOT NULL DEFAULT '',
    aliwap_buyer_email VARCHAR(64) NOT NULL DEFAULT '',
    aliwap_quantity int(10) unsigned NOT NULL DEFAULT '0',
    aliwap_gmt_payment TIMESTAMP,
    memo VARCHAR(256) NOT NULL DEFAULT '',
    val_pkg_3g4g VARCHAR(32) NOT NULL DEFAULT '',
    val_pkg_period int(10) unsigned NOT NULL DEFAULT '0',
    val_pkg_monthprice int(10) unsigned NOT NULL DEFAULT '0',
    val_pkg_plan VARCHAR(8) NOT NULL DEFAULT '',
    PRIMARY KEY (oid),
    KEY gh_id_oid(gh_id,oid),
    KEY gh_id_office_id(gh_id,office_id),
    KEY gh_id_aliwap_trade_no(gh_id,aliwap_trade_no),    
    KEY gh_id_idx(gh_id,openid)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


ALTER TABLE wx_order ADD scene_amt int(10) NOT NULL DEFAULT '0' after openid;
ALTER TABLE wx_order ADD scene_src_id int(10) unsigned NOT NULL DEFAULT '0' after openid;
ALTER TABLE wx_order ADD scene_id int(10) unsigned NOT NULL DEFAULT '0' after openid;

*/

use Yii;
use yii\db\ActiveRecord;
use yii\helpers\Security;
use yii\web\IdentityInterface;
use yii\behaviors\TimestampBehavior;
use app\models\U;
use app\models\MUser;
use app\models\MItem;
use app\models\MOffice;
use app\models\MSceneDetail;

class MOrder extends ActiveRecord
{
    const STATUS_AUTION = 0;
    const STATUS_OK = 3;        
    const STATUS_CLOSED_USER = 7;        
    const STATUS_CLOSED_AUTO = 9;            

    const PAY_KIND_CASH = 0;
    const PAY_KIND_ALIWAP = 1;
    const PAY_KIND_WECHAT = 2;

    const NO_CHOICE = 'null';
    
    public function attributeLabels()
    {
        return [
            'oid' => '订单号',
            'nickname' => '用户昵称',
            'title' => '商品名称',
            'cid' => '商品类别',
            'detail' => '商品详情',
            'feesum' => '支付金额',
            'status' => '订单状态',
            'select_mobnum'=>'手机号码',
            'create_time' => '创建时间',
            'userid' => '身份证',
            'username' => '姓名',
            'usermobile' => '联系电话',
            'address' => '收货地址',
            'kaitong' => '开通',
            'office_id' => '营业厅编号',
            'pay_kind' => '付款方式',
            'memo' => '留言',
        ];
    }

    public function rules()
    {
        return [
            [['status', 'pay_kind'], 'integer'],                    
            [['select_mobnum'],  'string', 'min' => 11, 'max' => 11],
            [['select_mobnum'],  'number'],  
            [['address'],  'string', 'min' => 5, 'max' => 256], 
            [['kaitong'],  'string', 'min' => 1, 'max' => 16],      
        ];
    }

    public function afterSave($insert, $changedAttributes)
    {        
        if (!empty($this->scene_id) && !empty($this->scene_amt))
        {
            if ($insert)
            {
                $ar = new MSceneDetail;
                $ar->scene_id = $this->scene_id;             
                $ar->scene_src_id = $this->scene_src_id;
                $ar->gh_id = $this->gh_id;
                $ar->openid = $this->openid;
                $ar->scene_amt = $this->scene_amt;
                $ar->oid = $this->oid;
                $ar->memo = $this->detail;                 
            }
            else
            {
            }
            $ar->status = $this->status == MOrder::STATUS_OK ? MSceneDetail::STATUS_CONFIRMED : MSceneDetail::STATUS_AUCTION;
            $ar->save(false);
{'fraction_non_alphanumeric': 0.12310104871116338, 'fraction_numerical': 0.025286680388121142, 'mean_word_length': 2.355475172640579, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1729565', 'n_tokens_mistral': 3531, 'n_tokens_neox': 3373, 'n_words': 889}