| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%agent_front_bind}}".
- *
- * @property integer $id
- * @property integer $front_agent_admin_id
- * @property integer $type_id
- * @property integer $type
- * @property integer $created_at
- * @property integer $updated_at
- * @property integer $is_delete
- * @property integer $status
- * @property integer $md_id
- */
- class AgentFrontBind extends \yii\db\ActiveRecord
- {
- const TYPE_SUPPLIER = 0;//供货商类型
- const TYPE_STORE = 1;//商家类型
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%agent_front_bind}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['updated_at', 'created_at'],
- ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'
- ]
- ]
- ];
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['id', 'front_agent_admin_id', 'type_id', 'type', 'created_at', 'updated_at', 'is_delete', 'status', 'md_id'], 'integer']
- ];
- }
- public static function getStoreBindFrontAgent($store_id) {
- return self::find()->alias('agb')->leftJoin(['a' => Admin::tableName()], 'agb.front_agent_admin_id = a.id')
- ->where(['agb.type' => self::TYPE_STORE, 'agb.type_id' => $store_id, 'agb.is_delete' => 0, 'agb.status' => 1])
- ->select('a.id front_agent_admin_id, a.name')->groupBy('a.id')->asArray()->all();
- }
- //获取仓库绑定的供货商
- public static function getAgentFrontBindSupplierId($front_agent_admin_id) {
- return self::find()->alias('a')
- ->leftJoin(['s' => Supplier::tableName()], 'a.type_id = s.id AND a.type = ' . self::TYPE_SUPPLIER)
- ->where([
- 'a.type' => self::TYPE_SUPPLIER,
- 'a.is_delete' => 0,
- 'a.status' => 1,
- 's.is_delete' => 0,
- 'a.front_agent_admin_id' => $front_agent_admin_id
- ])
- ->groupBy('s.cloud_supplier_id')
- ->select('s.cloud_supplier_id')->column();
- }
- }
|