| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use app\utils\OrderNo;
- use Yii;
- use yii\helpers\ArrayHelper;
- /**
- * This is the model class for table "{{%order_share}}".
- *
- * @property integer $id
- * @property integer $order_id
- * @property integer $cloud_order_id
- * @property integer $cloud_supplier_id
- * @property string $goods_info
- * @property string $order_detail_ids
- * @property integer $province_id
- * @property integer $city_id
- * @property integer $district_id
- * @property string $address
- * @property string $name
- * @property string $tel
- * @property integer $status
- * @property integer $is_delete
- * @property string $express_name
- * @property string $express_no
- * @property integer $send_type
- * @property integer $order_type
- * @property string $order_price
- * @property integer $confirm_time
- * @property integer $is_sale
- * @property integer $cancel_examine
- * @property string $cancel_examine_time
- * @property integer $created_at
- * @property integer $deleted_at
- * @property integer $is_use_platform_mch
- * @property integer $store_id
- * @property integer $goods_send_type
- */
- class OrderTransit extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%order_transit}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['id', 'order_id', 'cloud_order_id', 'cloud_supplier_id', 'province_id', 'city_id', 'confirm_time',
- 'district_id', 'status', 'is_delete', 'send_type', 'order_type', 'is_sale', 'cancel_examine', 'created_at', 'deleted_at', 'is_use_platform_mch', 'store_id', 'goods_send_type'],
- 'integer'],
- [['goods_info', 'order_detail_ids' , 'address' , 'name' , 'tel' , 'express_name' , 'express_no' ,
- 'order_price' , 'cancel_examine_time'], 'string'],
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => '',
- 'order_id' => '订单id',
- 'cloud_order_id' => '云仓转单id',
- 'cloud_supplier_id' => '云仓供货商id',
- 'goods_info' => '转单的商品信息',
- 'order_detail_ids' => 'oder_detail_id关联信息',
- 'province_id' => '省',
- 'city_id' => '市',
- 'district_id' => '区',
- 'address' => '地址详情',
- 'name' => '联系人',
- 'tel' => '联系电话',
- 'status' => '转单状态 -1取消 0 转单创建成功1 供货商已发货 2 已确认收货',
- 'is_delete' => '0未删除 1已删除',
- 'created_at' => '创建时间',
- 'deleted_at' => '删除时间',
- 'express_name' => '',
- 'express_no' => '',
- 'send_type' => '',
- 'order_type' => '订单类型',
- 'order_price' => '',
- 'confirm_time' => '确认收货时间',
- 'is_sale' => '是否过售后期',
- 'cancel_examine' => '是否申请售后 0未申请 1已申请 ',
- 'cancel_examine_time' => '取消时间',
- ];
- }
- public function afterOtherDataSave()
- {
- \app\modules\admin\models\jushuitan\JuShuiTanForm::afterTransitOrderSave($this);
- }
- public function afterSave($insert, $changedAttributes)
- {
- \app\modules\admin\models\jushuitan\JuShuiTanForm::afterTransitOrderSave($this, $insert, $changedAttributes);
- }
- public static function checkMdFrontBind($mch, $md_id = 0) {
- try {
- // $md_id = get_md_id();
- $mdAgentFrontBind = AgentFrontBind::findOne(['md_id' => $md_id, 'is_delete' => 0, 'status' => 1]);
- foreach ($mch['goods_list'] as $goods_item) {
- $goods_item['goods_name'] = mb_substr($goods_item['goods_name'], 0, 10);
- $supplierWhere = [
- 'is_delete' => 0,
- 'status' => 1,
- 'type' => AgentFrontBind::TYPE_SUPPLIER,
- ];
- //如果是云仓商品 且 配送方式为仓库配送 或集采
- if (intval($goods_item['cloud_goods_id']) && (intval($goods_item['is_front_delivery']) || intval($goods_item['is_front_centralize']))) {
- if (intval($goods_item['is_front_delivery'])) {
- if (!in_array($mch['send'], ['shop', 'delivery'])) {
- throw new \Exception('只能选择自提配送或同城配送');
- }
- }
- if (intval($goods_item['is_front_centralize'])) {
- if ($mch['send'] != 'shop') {
- throw new \Exception('只能选择自提配送');
- }
- }
- if ($mch['send'] === 'shop') {
- if ($md_id <= 0) {
- throw new \Exception('自提订单请选择门店');
- }
- //判断当前门店是否绑定仓库
- if (!$mdAgentFrontBind) {
- throw new \Exception('当前门店未拥有商品:'.$goods_item['goods_name'].'...的售卖权限,请尝试其他门店下单');
- }
- $supplierWhere['front_agent_admin_id'] = $mdAgentFrontBind->front_agent_admin_id;
- }
- if ($mch['send'] === 'delivery') {
- if ($md_id <= 0) {
- $goods = Goods::findOne($goods_item['goods_id']);
- if (!$goods) {
- throw new \Exception('商城商品' .$goods_item['goods_name']. '...状态异常');
- }
- $md = Md::findOne(['store_id' => $goods->store_id, 'is_delete' => 0, 'shop_audit' => Md::SHOP_AUDIT_YES]);
- if (!$md) {
- throw new \Exception('当前商城暂未创建门店不支持仓库同城配送');
- }
- $mdAgentFrontBind = AgentFrontBind::find()->where(['type' => AgentFrontBind::TYPE_STORE, 'type_id' => $goods->store_id, 'is_delete' => 0, 'status' => 1])
- ->andWhere(['>', 'md_id', 0])->select('front_agent_admin_id')->column();
- if (!$mdAgentFrontBind) {
- throw new \Exception('当前商城门店状态异常不能下单,请联系客服');
- }
- $supplierWhere['front_agent_admin_id'] = $mdAgentFrontBind;
- } else {
- //判断当前门店是否绑定仓库
- if (!$mdAgentFrontBind) {
- throw new \Exception('当前门店未拥有商品:'.$goods_item['goods_name'].'...的售卖权限,请尝试其他门店下单');
- }
- $supplierWhere['front_agent_admin_id'] = $mdAgentFrontBind->front_agent_admin_id;
- }
- }
- if (intval($goods_item['is_front_delivery'])) {
- $erpInventory = AgentFrontErpInventory::findOne(['goods_no' => $goods_item['goods_no'], 'goods_id' => $goods_item['cloud_goods_id']]);
- if (!$erpInventory) {
- throw new \Exception('商品' .$goods_item['goods_name']. '...仓库暂无货源');
- }
- if ($erpInventory->num <= $goods_item['num']) {
- throw new \Exception('商品' .$goods_item['goods_name']. '...仓库货源不足');
- }
- }
- $cloud_supplier_id = $goods_item['cloud_supplier_id'];
- //如果下单的产品的供货商绑定的仓库和门店没有绑定,那么不能下单
- if (!$cloud_supplier_id) {
- throw new \Exception('商品' .$goods_item['goods_name']. '...状态异常');
- }
- $supplier = Supplier::findOne(['cloud_supplier_id' => $cloud_supplier_id, 'is_delete' => 0]);
- if (!$supplier) {
- throw new \Exception('供货商' .$goods_item['goods_name']. '...状态异常');
- }
- $supplierWhere['type_id'] = $supplier->id;
- //判断当前商品供货商是否和门店仓库关联
- $supplierAgentFrontBind = AgentFrontBind::findOne($supplierWhere);
- if (!$supplierAgentFrontBind) {
- throw new \Exception('商品' .$goods_item['goods_name']. '...状态异常 不能下单 请联系客服');
- }
- }
- }
- return [
- 'code' => 0,
- 'msg' => 'success'
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- }
|