| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use app\jobs\order\OrderSendStringCodeRedPacketJob;
- use app\utils\AutoSendCoupon;
- use app\jobs\order\OrderCancelJob;
- use Yii;
- use Codeception\PHPUnit\ResultPrinter\HTML;
- use app\constants\OptionSetting;
- use app\models\Option;
- /**
- * This is the model class for table "{{%order}}".
- *
- * @property integer $id
- * @property integer $store_id
- * @property integer $user_id
- * @property integer $saas_id
- * @property string $order_no
- * @property string $total_price
- * @property string $send_price
- * @property string $take_price
- * @property string $pay_price
- * @property string $express_price
- * @property string $name
- * @property string $mobile
- * @property string $address
- * @property string $remark
- * @property integer $is_pay
- * @property integer $pay_type
- * @property integer $pay_time
- * @property integer $send_time
- * @property string $express
- * @property string $express_no
- * @property integer $confirm_time
- * @property integer $is_comment
- * @property integer $apply_delete
- * @property integer $supper_apply_delete
- * @property integer $created_at
- * @property integer $is_delete
- * @property integer $is_price
- * @property integer $parent_id
- * @property string $first_price
- * @property string $second_price
- * @property string $third_price
- * @property string $coupon_sub_price
- * @property string $content
- * @property integer $is_offline
- * @property integer $clerk_id
- * @property string $address_data
- * @property string $offline_qrcode
- * @property string $before_update_price
- * @property integer $shop_id
- * @property string $discount
- * @property integer $user_coupon_id
- * @property string $integral
- * @property integer $give_integral
- * @property integer $give_coin
- * @property integer $parent_id_1
- * @property integer $parent_id_2
- * @property integer $is_sale
- * @property string $words
- * @property string $version
- * @property string $express_price_1
- * @property integer $mch_id
- * @property integer $is_recycle
- * @property string $seller_comments
- * @property integer $order_union_id
- * @property string $rebate
- * @property string $before_update_express
- * @property integer $is_transfer
- * @property integer $type
- * @property string $share_price
- * @property integer $is_show
- * @property integer $order_origin
- * @property integer $is_open_offline
- * @property integer $trade_status
- * @property integer $is_settle
- * @property string $transaction_id
- * @property string $alipay_trade_no
- * @property string $adapay_payment_id
- * @property integer $adapay_share_finish
- * @property string $is_platform
- * @property integer $combine_money
- * @property integer $is_combine_pay
- * @property integer $order_type
- * @property string $book_info
- * @property string $updated_at
- * @property string $is_delivery
- * @property integer $md_id
- * @property integer $is_trans
- * @property integer $profit
- * @property integer $province_id
- * @property integer $city_id
- * @property integer $district_id
- * @property integer $town_id
- * @property integer $village_id
- * @property integer $food_flag_id
- * @property integer $food_book_ext
- * @property integer $pay_user_id
- * @property string $food_code
- * @property integer $ag_rebate
- * @property integer $verify_card_id
- * @property integer $holder_first_price
- * @property integer $holder_second_price
- * @property integer $holder_third_price
- * @property integer $holder_is_price
- * @property integer $share_send_type
- * @property integer $share_order_profit
- * @property integer $limit_id
- * @property integer $limit_price
- * @property integer $is_send_limit
- * @property integer $old_holder_first_price
- * @property integer $old_holder_second_price
- * @property integer $old_holder_third_price
- * @property integer $old_parent_id
- * @property integer $old_parent_id_1
- * @property integer $old_parent_id_2
- * @property string $get_verify_id
- * @property string $integral_difference_price
- * @property string $integral_price
- * @property integer $is_use_platform_mch
- * @property integer $buy_level_id
- * @property integer $level_order_id
- * @property integer $level_diff_price
- * @property string $hanging_order_id
- * @property integer $pt_order_id
- * @property string $activity_cut_price_order_id
- * @property string $activity_wechat_room_id
- * @property integer $trans_status
- * @property string $trans_error
- * @property integer $seckill_order_id
- * @property string $chain_level_value
- * @property string $level_price_json
- * @property string $get_coupon_id
- * @property string $rand_discount
- * @property integer $is_wastore
- * @property string $is_gross_profit
- * @property string $gross_profit
- * @property integer $md_group_activities_id
- * @property integer $md_group_activities_status
- * @property integer $is_yunst_sharing
- * @property string $huifu_id
- * @property string $trans_type
- * @property string $hf_seq_id
- * @property string $fee_amount
- * @property string $out_trans_id
- * @property string $party_order_id
- * @property string $req_seq_id
- * @property string $union_id
- * @property integer $string_code_reward_status
- * @property integer $make_concessions_status
- * @property integer $order_source
- */
- class Order extends \yii\db\ActiveRecord
- {
- /**
- * 订单流转状态:默认
- */
- const ORDER_FLOW_DEFAULT = -1;
- /**
- * 订单流转状态:待发货
- */
- const ORDER_FLOW_NO_SEND = 0;
- /**
- * 订单流转状态:已取消
- */
- const ORDER_FLOW_CANCEL = 1;
- /**
- * 订单流转状态:已发货
- */
- const ORDER_FLOW_SEND = 2;
- /**
- * 订单流转状态:已完成
- */
- const ORDER_FLOW_CONFIRM = 3;
- const TRADE_STATUS_TEXT = [
- self::ORDER_FLOW_DEFAULT => '待付款',
- self::ORDER_FLOW_NO_SEND => '待发货',
- self::ORDER_FLOW_SEND => '已发货',
- self::ORDER_FLOW_CANCEL => '已取消',
- self::ORDER_FLOW_CONFIRM => '已完成',
- ];
- public $valid_order_flow = [
- self::ORDER_FLOW_DEFAULT,
- self::ORDER_FLOW_NO_SEND,
- self::ORDER_FLOW_SEND,
- self::ORDER_FLOW_CANCEL,
- self::ORDER_FLOW_CONFIRM
- ];
- /**
- * 申请取消订单: 默认
- */
- const ORDER_APPLY_DELETE_DEFAULT = 0;
- /**
- * 申请取消订单: 申请中
- */
- const ORDER_APPLY_DELETE = 1;
- /**
- * 订单来源 公众号或网站
- */
- const ORDER_SOURCE_WEB = 1;
- /**
- * 订单来源 app
- */
- const ORDER_SOURCE_APP = 2;
- /**
- * 订单来源 小程序
- */
- const ORDER_SOURCE_MINI = 3;
- /**
- * 订单来源 收银台
- */
- const ORDER_SOURCE_CASHIER = 4;
- /**
- * 订单来源 后台录入
- */
- const ORDER_SOURCE_MANAGE = 5;
- /**
- * 用户取消类型
- */
- const CANCEL_USER_TYPE = 0;
- /**
- * 后台取消类型
- */
- const CANCEL_BACK_TYPE = 1;
- /**
- * 是否取消(手动):已取消
- */
- const IS_DELETE_TRUE = 1;
- /**
- * 是否取消(手动):未取消
- */
- const IS_DELETE_FALSE = 0;
- /**
- * 是否支付:已支付
- */
- const IS_PAY_TRUE = 1;
- /**
- * 是否支付:未支付
- */
- const IS_PAY_FALSE = 0;
- /**
- * 支付方式:未支付
- */
- const PAY_TYPE_UNPAID = 0;
- /**
- * 支付方式:微信支付
- */
- const PAY_TYPE_WECHAT = 1;
- const PAY_TYPE_KEY_WECHAT = 'wechat';
- /**
- * 支付方式:货到付款
- */
- const PAY_TYPE_COD = 2;
- /**
- * 支付方式:余额支付
- */
- const PAY_TYPE_BALANCE_PAID = 3;
- /**
- * 支付方式:支付宝支付
- */
- const PAY_TYPE_ALI = 4;
- const PAY_TYPE_KEY_ALI = 'alipay';
- /**
- * 支付方式:收银台钱包支付
- */
- const PAY_TYPE_CASHIER_PURSE = 6;
- /**
- * 支付方式:线下转账
- */
- const PAY_TYPE_OFFLINE = 11;
- const PAY_TYPE_KEY_OFFLINE = 'offline';
- const PAY_TYPE_NAME_OFFLINE = '线下转账';
- /**
- * 支付方式:每月月付
- */
- const PAY_TYPE_MONTH = 12;
- const PAY_TYPE_KEY_MONTH = 'month';
- const PAY_TYPE_NAME_MONTH = '每月月付';
- /**
- * 支付方式:yunst_pay通联支付
- */
- const PAY_TYPE_YUNST_WECHAT_PAY = 13;
- const PAY_TYPE_KEY_YUNST_WECHAT_PAY = 'yunst_wechat_pay';
- const PAY_TYPE_NAME_YUNST_WECHAT_PAY = '通联微信支付';
- /**
- * 支付方式:yunst_pay通联支付
- */
- const PAY_TYPE_YUNST_ALI_PAY = 14;
- const PAY_TYPE_KEY_YUNST_ALI_PAY = 'yunst_ali_pay';
- const PAY_TYPE_NAME_YUNST_ALI_PAY = '通联支付宝支付';
- /**
- * 支付方式:adapay_wx AdaPay微信支付
- */
- const PAY_TYPE_ADAPAY_WX = 101;
- const PAY_TYPE_KEY_ADAPAY_WX = 'adapay_wx';
- const PAY_TYPE_NAME_ADAPAY_WX = 'Adapay微信';
- /**
- * 支付方式:adapay_alipay AdaPay支付宝支付
- */
- const PAY_TYPE_ADAPAY_ALIPAY = 401;
- const PAY_TYPE_KEY_ADAPAY_ALIPAY = 'adapay_alipay';
- const PAY_TYPE_NAME_ADAPAY_ALIPAY = 'Adapay支付宝';
- /**
- * 支付方式:adapay_quickpay_frontpay AdaPay快捷支付
- */
- const PAY_TYPE_ADAPAY_QUICKPAY_FRONTPAY = 1001;
- const PAY_TYPE_KEY_ADAPAY_QUICKPAY_FRONTPAY = 'adapay_quickpay_frontpay';
- const PAY_TYPE_NAME_ADAPAY_QUICKPAY_FRONTPAY = 'AdaPay快捷';
- /**
- * 支付方式:聚合正扫
- * T_JSAPI: 微信公众号
- * T_MINIAPP: 微信小程序
- * T_H5:微信直连H5支付
- * T_APP:微信APP支付
- * T_NATIVE:微信正扫
- *
- * A_JSAPI: 支付宝JS
- * A_NATIVE: 支付宝正扫
- *
- * U_NATIVE: 银联正扫
- * U_JSAPI: 银联JS
- * D_NATIVE: 数字人民币正扫
- */
- const PAY_TYPE_HUIFU_WECHAT_PAY = 2000;
- const PAY_TYPE_KEY_HUIFU_WECHAT_PAY = 'huifu_wechat';
- const PAY_TYPE_NAME_HUIFU_WECHAT_PAY = '汇付微信支付';
- const PAY_TYPE_HUIFU_ALI_PAY = 2010;
- const PAY_TYPE_KEY_HUIFU_ALI_PAY = 'huifu_ali';
- const PAY_TYPE_NAME_HUIFU_ALI_PAY = '汇付支付宝支付';
- const PAY_TYPE_HUIFU_UNION_PAY = 2020;
- const PAY_TYPE_KEY_HUIFU_UNION_PAY = 'huifu_union';
- const PAY_TYPE_NAME_HUIFU_UNION_PAY = '汇付银联支付';
- const PAY_TYPE_QUICK_PAY = 3000;
- const PAY_TYPE_KEY_QUICK_PAY = 'quick_pay';
- const PAY_TYPE_NAME_QUICK_PAY = '快捷支付';
- const PAY_TYPE_HUIFU_PAYMENT_JSPAY_T_JSAPI = 2001;
- const PAY_TYPE_KEY_HUIFU_PAYMENT_JSPAY_T_JSAPI = 'huifu_payment_jspay_t_jsapi';
- const PAY_TYPE_NAME_HUIFU_PAYMENT_JSPAY_T_JSAPI = '汇付微信公众号';
- const PAY_TYPE_HUIFU_PAYMENT_JSPAY_T_MINIAPP = 2002;
- const PAY_TYPE_KEY_HUIFU_PAYMENT_JSPAY_T_MINIAPP = 'huifu_payment_jspay_t_miniapp';
- const PAY_TYPE_NAME_HUIFU_PAYMENT_JSPAY_T_MINIAPP = '汇付微信小程序';
- const PAY_TYPE_HUIFU_PAYMENT_JSPAY_A_JSAPI = 2003;
- const PAY_TYPE_KEY_HUIFU_PAYMENT_JSPAY_A_JSAPI = 'huifu_payment_jspay_a_jsapi';
- const PAY_TYPE_NAME_HUIFU_PAYMENT_JSPAY_A_JSAPI = '汇付支付宝JS';
- const PAY_TYPE_HUIFU_PAYMENT_JSPAY_UNION_JSAPI = 2021;
- const PAY_TYPE_KEY_HUIFU_PAYMENT_JSPAY_UNION_JSAPI = 'huifu_payment_jspay_union_jsapi';
- const PAY_TYPE_NAME_HUIFU_PAYMENT_JSPAY_UNION_JSAPI = '汇付银联JS';
- const PAY_TYPE_HUIFU_PAYMENT_JSPAY_UNION_NATIVE = 2022;
- const PAY_TYPE_KEY_HUIFU_PAYMENT_JSPAY_UNION_NATIVE = 'huifu_payment_jspay_union_native';
- const PAY_TYPE_NAME_HUIFU_PAYMENT_JSPAY_UNION_NATIVE = '汇付银联NATIVE';
- const PAY_TYPE_HUIFU_PAYMENT_JSPAY_T_H5 = 2005;
- const PAY_TYPE_KEY_HUIFU_PAYMENT_JSPAY_T_H5 = 'huifu_payment_jspay_t_h5';
- const PAY_TYPE_NAME_HUIFU_PAYMENT_JSPAY_T_H5 = '汇付微信直连H5支付';
- const PAY_TYPE_HUIFU_PAYMENT_JSPAY_T_APP = 2006;
- const PAY_TYPE_KEY_HUIFU_PAYMENT_JSPAY_T_APP = 'huifu_payment_jspay_t_app';
- const PAY_TYPE_NAME_HUIFU_PAYMENT_JSPAY_T_APP = '汇付微信APP支付';
- const PAY_TYPE_HUIFU_PAYMENT_A_NATIVE= 2007;
- const PAY_TYPE_KEY_HUIFU_PAYMENT_A_NATIVE = 'huifu_payment_a_native';
- const PAY_TYPE_NAME_HUIFU_PAYMENT_A_NATIVE = '汇付支付宝正扫';
- const PAY_TYPE_KEY_YSDL = 'ysdl';
- const PAY_TYPE_NAME_YSDL = '云数动力';
- /**
- * 订单类型:商城订单
- */
- const ORDER_TYPE_STORE = 0;
- /**
- * 订单类型:当面付订单
- */
- const ORDER_TYPE_POND = 1;
- /**
- * 订单类型:认养订单
- */
- const ORDER_TYPE_Adopt = 5;
- /**
- * 订单类型:上门服务订单
- */
- const ORDER_TYPE_WORKER = 6;
- const ORDER_TYPE_EXT_WORKER_FIRST_PAY = 601; //定金订单
- const ORDER_TYPE_EXT_WORKER_LAST_PAY = 602; //尾款订单
- const ORDER_TYPE_EXT_WORKER_ADD_TIME = 603; //加钟订单
- const ORDER_TYPE_INTEGRAL = 7;
- //活动类型
- const ACTIVITY_TYPE_CUT_PRICE = 1;
- //拼团活动类型
- const ACTIVITY_PT_PRICE = 2;
- //秒杀活动类型
- const ACTIVITY_SECKILL_PRICE = 3;
- //群优惠活动类型
- const ACTIVITY_WECHAT_ROOM = 4;
- /**
- * 订单是否显示:显示
- */
- const IS_SHOW_TRUE = 1;
- /**
- * 订单是否显示:不显示
- */
- const IS_SHOW_FALSE = 0;
- /**
- * 是否过售后时间:是
- */
- const IS_SALE_TRUE = 1;
- /**
- * 是否过售后时间:否
- */
- const IS_SALE_FALSE = 0;
- /**
- * 自提订单
- */
- const IS_OFFLINE_TRUE = 1;
- const IS_OFFLINE_FALSE = 0;
- /**
- * 类型
- */
- // const SEND_TYPE_DADA = 1;
- // const SEND_TYPE_UU = 2;
- // const SEND_TYPE_PEISONG = 3;
- /**
- * 同城配送
- */
- const IS_SAME_CITY_NO = 0; //否
- const IS_SAME_CITY_YES = 1; //是
- /**
- * 是否是组合支付:是
- */
- const IS_COMBINE_PAY = 1;
- /**
- * 是否是组合支付:否
- */
- const NOT_COMBINE_PAY = 0;
- /**
- * 订单支付方式
- */
- const PAY_TYP_NAME = [
- 0=>'未支付',
- 1=>'微信支付',
- 2=>'货到付款',
- 3=>'余额支付',
- 4=>'支付宝支付',
- 5=>'抖音支付',
- 6=>'线下支付',
- self::PAY_TYPE_OFFLINE => self::PAY_TYPE_NAME_OFFLINE,
- self::PAY_TYPE_MONTH => self::PAY_TYPE_NAME_MONTH,
- self::PAY_TYPE_ADAPAY_WX => self::PAY_TYPE_NAME_ADAPAY_WX,
- self::PAY_TYPE_ADAPAY_ALIPAY => self::PAY_TYPE_NAME_ADAPAY_ALIPAY,
- self::PAY_TYPE_ADAPAY_QUICKPAY_FRONTPAY => self::PAY_TYPE_NAME_ADAPAY_QUICKPAY_FRONTPAY,
- self::PAY_TYPE_HUIFU_WECHAT_PAY => self::PAY_TYPE_NAME_HUIFU_WECHAT_PAY,
- self::PAY_TYPE_HUIFU_ALI_PAY => self::PAY_TYPE_NAME_HUIFU_ALI_PAY,
- ];
- /**
- * 订单支付方式
- */
- const HUIFU_PAYMENT_TYPE = [
- self::PAY_TYPE_HUIFU_WECHAT_PAY,
- self::PAY_TYPE_HUIFU_ALI_PAY,
- ];
- /**
- * 订单支付方式
- */
- const HUIFU_PAYMENT_PAY_TYPE = [
- self::PAY_TYPE_HUIFU_PAYMENT_JSPAY_T_JSAPI => 'T_JSAPI',
- self::PAY_TYPE_HUIFU_PAYMENT_JSPAY_T_MINIAPP => 'T_MINIAPP',
- self::PAY_TYPE_HUIFU_PAYMENT_JSPAY_A_JSAPI => 'A_JSAPI',
- self::PAY_TYPE_HUIFU_PAYMENT_JSPAY_UNION_NATIVE => 'U_NATIVE',
- self::PAY_TYPE_HUIFU_PAYMENT_JSPAY_UNION_JSAPI => 'U_JSAPI',
- self::PAY_TYPE_HUIFU_PAYMENT_JSPAY_T_H5 => 'T_H5',
- self::PAY_TYPE_HUIFU_PAYMENT_JSPAY_T_APP => 'T_APP',
- self::PAY_TYPE_HUIFU_PAYMENT_A_NATIVE => 'A_NATIVE',
- ];
- /**
- * 微信参数集合
- */
- const WX_DATA_PAY_TYPE = [
- self::PAY_TYPE_HUIFU_PAYMENT_JSPAY_T_JSAPI,
- self::PAY_TYPE_HUIFU_PAYMENT_JSPAY_T_MINIAPP,
- self::PAY_TYPE_HUIFU_PAYMENT_JSPAY_T_H5,
- self::PAY_TYPE_HUIFU_PAYMENT_JSPAY_T_APP
- ];
- /**
- * 支付宝参数集合支付方式
- */
- const ALIPAY_DATA_PAY_TYPE = [
- self::PAY_TYPE_HUIFU_PAYMENT_JSPAY_A_JSAPI
- ];
- /**
- * 银联参数集合支付方式
- */
- const UNION_JSAPI_DATA_PAY_TYPE = [
- self::PAY_TYPE_HUIFU_PAYMENT_JSPAY_UNION_JSAPI,
- self::PAY_TYPE_HUIFU_PAYMENT_JSPAY_UNION_NATIVE
- ];
- const FROM_APP = 'app';
- const FROM_MINI = 'mini';
- const FROM_H5 = 'h5';
- const FROM_OFFICIAL = 'official';
- const PLATFORM_FROM_UNION = 'union'; //联盟端
- const PLATFORM_FROM_SAAS= 'saas'; //saas独立小程序端
- const PLATFORM_FROM_H5= 'h5'; //联盟h5端
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%order}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['store_id', 'user_id', 'order_no', 'first_price', 'second_price', 'third_price'], 'required'],
- [['store_id', 'user_id', 'is_pay', 'pay_type', 'pay_time', 'send_time',
- 'confirm_time', 'is_comment', 'apply_delete', 'supper_apply_delete', 'created_at', 'updated_at', 'is_delete', 'is_price', 'parent_id',
- 'is_offline', 'clerk_id', 'shop_id', 'user_coupon_id', 'give_integral', 'give_coin', 'parent_id_1',
- 'parent_id_2', 'old_parent_id', 'old_parent_id_1', 'old_parent_id_2', 'is_sale', 'mch_id', 'order_union_id', 'is_transfer', 'type', 'is_show',
- 'is_open_offline', 'order_origin', 'trade_status', 'is_platform', 'is_combine_pay', 'order_type',
- 'is_delivery', 'md_id', 'is_trans', 'province_id', 'city_id', 'district_id', 'town_id', 'village_id', 'food_flag_id', 'pay_user_id', 'verify_card_id', 'holder_is_price', 'share_send_type','limit_id', 'is_send_limit','integral_price', 'is_use_platform_mch', 'buy_level_id', 'level_order_id', 'hanging_order_id', 'pt_order_id', 'saas_id','md_group_activities_id','md_group_activities_status'], 'integer'],
- [['total_price', 'pay_price', 'rand_discount', 'express_price', 'first_price', 'second_price', 'third_price',
- 'coupon_sub_price', 'before_update_price', 'discount', 'express_price_1', 'rebate',
- 'before_update_express', 'share_price', 'combine_money', 'profit', 'ag_rebate', 'holder_first_price', 'holder_second_price', 'holder_third_price', 'old_holder_first_price', 'old_holder_second_price', 'old_holder_third_price', 'share_order_profit', 'limit_price','integral_difference_price', 'level_diff_price', 'trans_status', 'seckill_order_id', 'take_price', 'send_price', 'sort'], 'number'],
- [['address_data', 'content', 'offline_qrcode', 'integral', 'words', 'seller_comments', 'book_info', 'food_book_ext', 'food_code', 'get_verify_id', 'get_coupon_id', 'union_id'], 'string'],
- [['order_no', 'name', 'mobile', 'express', 'express_no', 'version', 'alipay_trade_no', 'trans_error'], 'string', 'max' => 255],
- [['address', 'remark', 'shop_remark'], 'string', 'max' => 1000],
- [['md_id','ready_money','sale_time', 'activity_cut_price_order_id', 'activity_wechat_room_id'], 'safe'],
- [['delivery_time', 'adapay_payment_id', 'adapay_share_finish', 'chain_level_value', 'level_price_json', 'is_gross_profit', 'gross_profit'], 'safe'],
- [['transaction_id', 'tax_price', 'is_wastore'], 'safe'],
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'store_id' => 'Store ID',
- 'user_id' => '用户id',
- 'saas_id' => '联盟用户id',
- 'order_no' => '订单号',
- 'total_price' => '订单总费用(包含运费)',
- 'pay_price' => '实际支付总费用(含运费)',
- 'express_price' => '运费',
- 'send_price' => 'send_price',
- 'take_price' => 'take_price',
- 'integral_price' => '积分数量',
- 'integral_difference_price' => '补积分差价',
- 'name' => '收货人姓名',
- 'mobile' => '收货人手机',
- 'address' => '收货地址',
- 'remark' => '订单备注',
- 'is_pay' => '支付状态:0=未支付,1=已支付',
- 'pay_type' => '支付方式:1=微信支付',
- 'pay_time' => '支付时间',
- 'send_time' => '发货时间',
- 'express' => '物流公司',
- 'express_no' => 'Express No',
- 'confirm_time' => '确认收货时间',
- 'is_comment' => '是否已评价:0=未评价,1=已评价',
- 'apply_delete' => '是否申请取消订单:0=否,1=申请取消订单',
- 'supper_apply_delete' => '是否申请供应商取消订单:0否 1申请取消',
- 'created_at' => 'Addtime',
- 'is_delete' => 'Is Delete',
- 'is_price' => '是否发放佣金',
- 'parent_id' => '用户上级ID',
- 'first_price' => '一级佣金',
- 'second_price' => '二级佣金',
- 'third_price' => '三级佣金',
- 'coupon_sub_price' => '优惠券抵消金额',
- 'content' => 'Content',
- 'is_offline' => '是否到店自提 0--否 1--是',
- 'clerk_id' => '核销员user_id',
- 'address_data' => '收货地址信息,json格式',
- 'offline_qrcode' => '核销码',
- 'before_update_price' => '修改前的价格',
- 'shop_id' => '自提自提点ID',
- 'discount' => '会员折扣',
- 'user_coupon_id' => '使用的优惠券ID',
- 'integral' => '积分使用',
- 'give_integral' => '是否发放积分【1=> 已发放 , 0=> 未发放】',
- 'give_coin' => '是否发放积分【1=> 已发放 , 0=> 未发放】',
- 'parent_id_1' => '用户上二级ID',
- 'parent_id_2' => '用户上三级ID',
- 'is_sale' => '是否超过售后时间',
- 'words' => '商家留言',
- 'version' => '版本',
- 'express_price_1' => '减免的运费',
- 'mch_id' => '入驻商户id',
- 'seller_comments' => '商家备注',
- 'order_union_id' => '合并订单的id',
- 'rebate' => '自购返利',
- 'before_update_express' => '价格修改前的运费',
- 'is_transfer' => '是否已转入商户账户:0=否,1=是',
- 'type' => '0普通订单1卡券兑换订单',
- 'share_price' => '发放佣金的金额',
- 'is_show' => '是否显示 0--不显示 1--显示(软删除用)',
- 'order_origin' => '订单来源 1:公众号或者网站 2:app 3:小程序 4:收银台',
- 'is_open_offline' => '是否是线下购物车下的订单',
- 'trade_status' => '订单状态,-1:默认,0:待发货,1:已取消,2:已发货,3:已确认',
- "limit_id"=>"临时关系ID",
- 'limit_price' => "临时绑定关系订单佣金",
- 'is_send_limit' => "是否发放临时关系佣金",
- 'get_verify_id' => '获取的卡券id',
- 'is_use_platform_mch' => '供应链系统下单时是否使用平台商户号,1使用,0未使用',
- 'sale_time' => '收银台销售时间',
- 'ready_money' => '现金支付相关',
- 'hanging_order_id' => '挂单订单id',
- 'activity_cut_price_order_id' => '砍价订单id',
- 'pt_order_id' => "拼团订单id",
- 'trans_error' => '转单错误信息',
- 'trans_status' => '转单状态',
- 'chain_level_value' => '等级链动佣金',
- 'get_coupon_id' => '优惠券id',
- 'rand_discount' => '随机立减',
- 'is_gross_profit' => '毛利润已计算',
- 'gross_profit' => '毛利润',
- 'md_group_activities_id' => '订单对应活动门店团购活动ID',
- 'md_group_activities_status' => '订单对应门店团购状态',
- 'make_concessions_status' => '商城让利合伙人 1:已发放,0:否',
- ];
- }
- public function getOrderDetail()
- {
- return $this->hasMany(OrderDetail::className(), ['order_id' => 'id'])->alias('od')
- ->leftJoin(['g' => Goods::tableName()], 'g.id=od.goods_id')->select(['od.*', 'g.name', 'g.attr goods_attr', 'g.cost_price']);
- }
- public function getDetail()
- {
- return $this->hasMany(OrderDetail::className(), ['order_id' => 'id']);
- }
- public function getGoods()
- {
- return $this->hasMany(Goods::className(), ['id' => 'goods_id'])->alias('g')
- ->viaTable(OrderDetail::tableName() . ' od', ['order_id' => 'id']);
- }
- public function getShop()
- {
- return $this->hasOne(Shop::className(), ['id' => 'shop_id']);
- }
- public function getClerk()
- {
- return $this->hasOne(User::className(), ['id' => 'clerk_id']);
- }
- public function getOrderForm()
- {
- return $this->hasMany(OrderForm::className(), ['order_id' => 'id'])->where(['is_delete' => 0]);
- }
- public function getUser()
- {
- return $this->hasOne(User::className(), ['id' => 'user_id']);
- }
- public function getRefund()
- {
- return $this->hasMany(OrderRefund::className(), ['order_id' => 'id']);
- }
- public function beforeSave($insert)
- {
- $this->content = \yii\helpers\Html::encode($this->content);
- if($this->trade_status == self::ORDER_FLOW_CONFIRM){
- if(empty($this->send_time)){
- $this->send_time = time();
- }
- }
- return parent::beforeSave($insert);
- }
- public function afterOtherDataSave()
- {
- \app\modules\admin\models\jushuitan\JuShuiTanForm::afterOrderSave($this);
- \app\modules\admin\models\WastoreForm::afterOrderOtherDataSave($this);
- }
- public function afterSave($insert, $changedAttributes)
- {
- debug_log([__METHOD__, __LINE__, "========start====== 商城订单:【{$this->id}】 订单状态:{$this->trade_status} 订单来源:{$this->order_source}"], "app_debug.log");
- if ($this->order_source == 1) return;
- parent::afterSave($insert, $changedAttributes);
- if($this->user_id && $this->store_id && ($this->trade_status == self::ORDER_FLOW_CONFIRM)){
- if(isset($changedAttributes['trade_status']) && ($changedAttributes['trade_status'] != self::ORDER_FLOW_CONFIRM)){
- $query = self::find()->where(['user_id' => $this->user_id, 'store_id' => $this->store_id, 'trade_status' => self::ORDER_FLOW_CONFIRM]);
- $count = $query->count();
- if($count == 1){
- // 赠送优惠券
- \app\utils\AutoSendCoupon::send($this->user_id, CouponAutoSend::EVENT_NEWUSER, $this->store_id, 0, CouponAutoSend::EXT_FIRST_ORDER);
- }
- if($count == 2){
- // 赠送优惠券
- \app\utils\AutoSendCoupon::send($this->user_id, CouponAutoSend::EVENT_NEWUSER, $this->store_id, 0, CouponAutoSend::EXT_SECOND_ORDER);
- }
- }
- }
- Worker::afterOrderSave($insert, $changedAttributes, $this);
- BookingOrderExt::afterOrderSave($insert, $changedAttributes, $this);
- \app\modules\admin\models\maiyatian\MaiyatianForm::afterOrderSave($insert, $changedAttributes, $this);
- \app\modules\admin\models\keloop\KeloopForm::afterOrderSave($insert, $changedAttributes, $this);
- \app\modules\admin\models\jushuitan\JuShuiTanForm::afterOrderSave($this, $changedAttributes);
- \app\models\ActivityRebateOrderNLog::afterOrderSave($insert, $changedAttributes, $this);
- \app\modules\admin\models\WastoreForm::afterOrderSave($insert, $changedAttributes, $this);
- \app\modules\admin\models\erp\InventoryForm::afterOrderSave($this, $insert, $changedAttributes);
- // 处理订单自动确认收货
- if (!$insert && isset($changedAttributes['trade_status']) && $this->trade_status == self::ORDER_FLOW_SEND && $this->order_source == 0) {
- $delivery_time = Option::get(OptionSetting::STORE_DELIVERY_TIME, $this->store_id, 'store', 0)['value'];
- //debug_log([__METHOD__, __LINE__, "处理订单自动确认收货:【{$this->id}】 售后时间:{$delivery_time}"], "app_debug.log");
- if ($delivery_time !== null) {
- $job = new \app\jobs\order\AutoConfirmOrderJob();
- $job->order_id = $this->id;
- $job->store_id = $this->store_id;
- $qid = \queue_push($job, (int)$delivery_time * 86400);
- }
- (new \app\utils\Share\BonusPool())->handleOrderAuto($this);
- }
- if (isset($changedAttributes['is_pay']) && $this->is_pay == self::IS_PAY_TRUE) {
- // (new \app\utils\OrderUtil())->OrderGrossProfit($this);
- // (new \app\utils\Share\BonusPool())->handleOrderAuto($this);
- // // \queue_push(new OrderSendStringCodeRedPacketJob(['order_id' => $this->id, 'is_scan' => 0]), 5);
- // // new OrderSendStringCodeRedPacketJob(['order_id' => $this->id, 'is_scan' => 0]);
- // // 创建任务实例
- // $job = new OrderSendStringCodeRedPacketJob(['order_id' => $this->id, 'is_scan' => 0]);
- // // 直接调用 execute() 方法来执行任务
- // $job->execute(null); // 如果不需要传递队列对象,可以传递 null
- //debug_log([__METHOD__, __LINE__, "============== 商城订单:【{$this->id}】 执行确认支付动作 =============="], "app_debug.log");
- }
- if (isset($changedAttributes['trade_status']) && $this->trade_status == self::ORDER_FLOW_CONFIRM) {
- // (new \app\utils\OrderUtil())->OrderGrossProfit($this);
- // (new \app\utils\Share\BonusPool())->handleOrderAuto($this);
- // // \queue_push(new OrderSendStringCodeRedPacketJob(['order_id' => $this->id, 'is_scan' => 0]), 5);
- // // new OrderSendStringCodeRedPacketJob(['order_id' => $this->id, 'is_scan' => 0]);
- // // 创建任务实例
- // $job = new OrderSendStringCodeRedPacketJob(['order_id' => $this->id, 'is_scan' => 0]);
- // // 直接调用 execute() 方法来执行任务
- // $job->execute(null); // 如果不需要传递队列对象,可以传递 null
- //debug_log([__METHOD__, __LINE__, "============== 商城订单:【{$this->id}】 执行确认收货动作 =============="], "app_debug.log");
- }
- // 处理订单确认收货后要做的事情
- if (!$insert && isset($changedAttributes['trade_status']) && $this->trade_status == self::ORDER_FLOW_CONFIRM && $this->order_source == 0) {
- //debug_log([__METHOD__, __LINE__, "============== 处理订单确认收货后id:【{$this->id}】 =============="], "app_debug.log");
- $after_sale_time = Option::get(OptionSetting::STORE_AFTER_SALE_TIME, $this->store_id, 'store', 0)['value'];
- $job = new \app\jobs\order\NoAfterSalesOrderJob();
- $job->order_id = $this->id;
- $job->store_id = $this->store_id;
- $delay = 0;
- if ($after_sale_time > 0) {
- $delay = $after_sale_time * 86400;
- }
- //需要兼容通联支付 t+1今天支付 明天的冻结余额才会增加 不能立即分账 否则出问题
- if (intval($this->pay_type) === self::PAY_TYPE_YUNST_WECHAT_PAY) {
- $today0 = strtotime(date('Y-m-d'));//今天0点时间
- if ($this->pay_time > $today0 && $delay < 86400) {
- $tomoTime = strtotime(date('Y-m-d', strtotime("+1 day"))) + 39600;
- $delay = $tomoTime - time();
- }
- }
- //兼容可能出现的股东分红会优先发放但是股东分红还未生成的情况
- //创建股东分红在订单支付之后 可能执行较慢 但是队列此时可能已经添加成功,可能会优先执行队列 导致先发后创建的问题
- if ($delay <= 0) {
- // $delay = 60;
- $delay = 10;
- }
- //debug_log([__METHOD__, __LINE__, "============== 重新执行 Order afterSave NoAfterSalesOrderJob,id:".$this->id." =======store_id:".$this->store_id."======="], "app_debug.log");
- \queue_push($job, $delay);
- \app\utils\Share\BonusPool::ShareHolderLevelJob($this->store_id, 0, $this->user_id);
- AutoSendCoupon::send($this->user_id, CouponAutoSend::EVENT_ORDER, $this->store_id);
- self::stbzConfirm($this);
- }
- if ($insert && in_array($this->order_type, [1,2])) {
- $autoCancleTime = \app\utils\OrderUtil::getAutoCancelTime($this->store_id);
- \queue_push(new \app\jobs\order\OrderBookNoPayJob(['order_id' => $this->id]), $autoCancleTime);
- }
- // if (($insert && $this->is_pay == 1) || (isset($changedAttributes['is_pay']) && $this->is_pay == 1)) {
- // (new \app\utils\OrderUtil())->OrderGrossProfit($this);
- // (new \app\utils\Share\BonusPool())->handleOrderAuto($this);
- // \queue_push(new OrderSendStringCodeRedPacketJob(['order_id' => $this->id, 'is_scan' => 0]), 5);
- // }
- if ($this->store_id && $this->user_id && !cache_lock(['ShareLevelJob', $this->store_id, $this->user_id], 30)) {
- \queue_push(new \app\jobs\ShareLevelJob(['store_id' => $this->store_id, 'user_id' => $this->user_id]), 30, 1);
- }
- if (!$insert && isset($changedAttributes['trade_status'])) {
- $res = \queue_push(new \app\jobs\AlipayThirdOrderJob(['order_id' => $this->id]), 5);
- }
- if ($insert && $this->trade_status == self::ORDER_FLOW_DEFAULT) {
- \queue_push(new OrderCancelJob(['order_id' => $this->id]), 900);
- }
- }
- public static function stbzGoodsHas($order) {
- $og = $order->goods;
- foreach($og as $item){
- if($item['stbz_goods_id']){
- return true;
- }
- }
- return false;
- }
- public static function stbzOrder($orderId) {
- try{
- $orderTransit = OrderTransit::findOne(['order_id' => $orderId, 'is_delete' => 0]);
- // var_dump($orderTransit->attributes);
- if($orderTransit){
- $thirdSn = $orderTransit->cloud_order_no;
- $stbzOrder = \stbz_client()->getApiResponse('get', '/v2/order', [
- 'search' => [
- 'thirdSn' => $thirdSn,
- ],
- 'page' => 1,
- 'limit' => 1,
- ]);
- $returnData = \json_decode($stbzOrder, true);
- // var_dump($returnData);
- if ($returnData['code'] == 1) {
- if($returnData['data'] && $returnData['data']['list']){
- foreach($returnData['data']['list'] as $orderList){
- return $orderList;
- }
- }
- }
- }
- } catch (\Exception $ex) {
- \Yii::error($ex);
- }
- return [];
- }
- public static function stbzConfirm($order) {
- try{
- $goods_sns = [];
- $orderList = self::stbzOrder($order->id);
- if($orderList['children']){
- foreach($orderList['children'] as $children){
- if($children['goods']){
- foreach($children['goods'] as $goods){
- $goods_sns[] = $goods['sn'];
- }
- }
- }
- }
- // var_dump($goods_sns);die;
- foreach($goods_sns as $goods_sn){
- $confirm = \stbz_client()->getApiResponse('post', '/v2/logistic/confirm', [
- 'goods_sn' => $goods_sn,
- ]);
- \Yii::error([__METHOD__, __LINE__, $order->id, $order->order_no, $orderList, $goods_sn, $confirm]);
- // var_dump($confirm);die;
- }
- } catch (\Exception $ex) {
- \Yii::error($ex);
- }
- }
- public function getPondDetail()
- {
- return $this->hasOne(OrderDetail::className(), ['order_id' => 'id']);
- }
- public function getPondGoods()
- {
- return $this->hasOne(Goods::className(), ['id' => 'goods_id'])->alias('g')
- ->viaTable(OrderDetail::tableName() . ' od', ['order_id' => 'id']);
- }
- public function getReceiver(){
- return $this->hasOne(SharingReceiver::className(),['order_no'=>'order_no']);
- }
- public function getStore(){
- return $this->hasOne(Store::className(),['id'=>'store_id']);
- }
- public static function getWxOrderLocalType($store_id, $order_no, $order) {
- /**
- *
- '1'=> [
- 'text' => '统一为快递',
- 'value' => 0
- ],
- '2' => [
- 'text' => '统一为同城配送',
- 'value' => 1
- ],
- '3' => [
- 'text' => '统一为虚拟发货',
- 'value' => 0
- ],
- '4' => [
- 'text' => '统一为用户自提',
- 'value' => 0
- ],
- '100' => [
- 'text' => '使用订单发货方式',
- 'value' => 0
- ],
- */
- $wx_local_type = Option::get(OptionSetting::STORE_WX_LOGISTICS_TYPE, $store_id)['value'];
- if(!$wx_local_type){
- $wx_local_type = 2;
- }
- if($wx_local_type == 1 && empty($order['express_no'])){
- $wx_local_type = 2;
- }
- if($wx_local_type == '100'){
- $wx_local_type = 2;
- $order = Order::findOne(['transaction_id' => $order_no]);
- if($order){
- $wx_local_type = 1;
- if($order['order_origin'] == Order::ORDER_SOURCE_CASHIER){
- $wx_local_type = 4;
- }
- if($order['order_type'] == Order::ORDER_TYPE_WORKER){
- $wx_local_type = 2;
- }
- if($order['is_delivery'] == 1){
- $wx_local_type = 2;
- }
- if($order['is_offline'] == 1){
- $wx_local_type = 4;
- }
- }
- }
- ////debug_log([__METHOD__, __LINE__, "====================|wx_local_type:".$wx_local_type], "app_debug_auto_cash_apply.log");
- return $wx_local_type;
- }
- public static function getStatusText($tradeStatus): string
- {
- return self::TRADE_STATUS_TEXT[$tradeStatus];
- }
- }
|