|
- <?php
-
- namespace backend\modules\api\models;
-
- use backend\modules\zzcs\models\BaseSupplierPurchase;
- use backend\modules\zzcs\models\BaseSupplierSale;
- use yii\db\ActiveRecord;
- use yii\data\ActiveDataProvider;
- use Yii;
-
- /**
- * This is the model class for table "base_supplier".
- *
- * @property integer $ID
- * @property integer $MAIN_CORP_ID
- * @property integer $CREATE_USER_ID
- * @property string $CREATE_TIME
- * @property integer $UPDATE_USER_ID
- * @property string $UPDATE_TIME
- * @property integer $CANCEL_FLAG
- * @property integer $AREA_ID
- * @property integer $SUPPLIER_TYPE
- * @property string $SUPPLIER_NAME
- * @property string $SUPPLIER_CODE
- * @property integer $MANAGE_TYPE
- * @property string $COMPANY_NAME
- * @property string $ID_CARD
- * @property integer $IS_DISABLED
- * @property integer $SETT_TYPE
- * @property integer $SETT_FREQUENCY
- * @property string $ACCOUNT_BANK
- * @property string $ACCOUNT_NUM
- * @property string $ACCOUNT_NAME
- * @property string $SALES_MAN
- */
- class BaseSupplier extends ActiveRecord
- {
- public $product_type;
- public $status;
-
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'base_supplier';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['MAIN_CORP_ID', 'CREATE_USER_ID', 'UPDATE_USER_ID', 'CANCEL_FLAG', 'AREA_ID', 'SUPPLIER_TYPE', 'MANAGE_TYPE', 'IS_DISABLED', 'SETT_TYPE', 'SETT_FREQUENCY'], 'integer'],
- [['CREATE_TIME', 'SUPPLIER_TYPE', 'SUPPLIER_NAME'], 'required'],
- [['UPDATE_TIME'], 'safe'],
- [['CREATE_TIME', 'ID_CARD', 'ACCOUNT_NUM'], 'string', 'max' => 20],
- [['SUPPLIER_NAME', 'SUPPLIER_CODE', 'COMPANY_NAME', 'ACCOUNT_BANK', 'ACCOUNT_NAME'], 'string', 'max' => 100],
- [['SALES_MAN'], 'string', 'max' => 30],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ID' => 'ID',
- 'MAIN_CORP_ID' => '运营主体ID',
- 'CREATE_USER_ID' => '记录创建用户ID',
- 'CREATE_TIME' => '记录创建时间',
- 'UPDATE_USER_ID' => '记录最后更新用户ID',
- 'UPDATE_TIME' => '记录最后更新时间',
- 'CANCEL_FLAG' => '记录有效性标记,CANCEL_FLAG=0记录有效;CANCEL_FLAG=1,记录已删除',
- 'AREA_ID' => '所属区域',
- 'SUPPLIER_TYPE' => '供应商或渠道商标志 187:供应商 ',
- 'SUPPLIER_NAME' => '供应商或渠道商名称',
- 'SUPPLIER_CODE' => '代码',
- 'MANAGE_TYPE' => '经营性质 1:公司 2:个人',
- 'COMPANY_NAME' => '公司名称',
- 'ID_CARD' => '身份证号',
- 'IS_DISABLED' => '0:正常 1:停用',
- 'SETT_TYPE' => '结算方式,对应DICT_TYPE.ID',
- 'SETT_FREQUENCY' => '结算周期,对应DICT_TYPE.ID',
- 'ACCOUNT_BANK' => '开户银行',
- 'ACCOUNT_NUM' => '银行账号',
- 'ACCOUNT_NAME' => '账号名称 PRIMARY KEY (`ID`)',
- 'SALES_MAN' => 'Sales Man',
- ];
- }
-
- public function getdepart_status()
- {
- return $this->hasOne(DictType::className(), ['ID' => 'STATUS']);
- }
-
- public function getBaseSupplierPurchase()
- {
- return $this->hasMany(BaseSupplierPurchase::className(), ['SUPPLIER_ID' => 'ID']);
- }
-
- public function getBaseSupplierSale()
- {
- return $this->hasMany(BaseSupplierSale::className(), ['SUPPLIER_ID' => 'ID']);
- }
-
- /**
- * 获取供应商列表
- */
- public function getSupplierList()
- {
- $res = BaseSupplier::find()
- ->select(['a.ID', 'a.SUPPLIER_NAME'])
- ->innerJoinWith('baseSupplierPurchase as b')
- ->from('base_supplier as a')
- ->where(['b.PRODUCT_TYPE' => 25, 'a.SUPPLIER_TYPE' => 187, 'a.cancel_flag' => 0, 'b.cancel_flag' => 0, 'a.MAIN_CORP_ID' => 1])
- ->groupBy('b.SUPPLIER_ID')->asArray()->all();
-
- return $res;
- }
-
- /**
- * @Author wanglg
- * @Desc 获取渠道商列表
- *
- */
- public function getChannelList()
- {
- $res = BaseSupplier::find()
- ->select(['DISTINCT(a.ID)', 'a.SUPPLIER_NAME'])
- ->joinWith('baseSupplierSale as b')
- ->from('base_supplier as a')
- ->where(['b.PARENT_TYPE' => 25, 'a.SUPPLIER_TYPE' => 301, 'a.cancel_flag' => 0, 'a.IS_DISABLED' => 0, 'b.cancel_flag' => 0, 'a.MAIN_CORP_ID' => 1])
- // ->createCommand() -> getRawSql();
- ->asArray()->all();
-
- return $res;
- }
-
- /**
- * @Author wanglg
- * @Desc 获取排序的渠道商列表
- * @return array|ActiveRecord[]
- */
- public function getOrderChannelList()
- {
- $res = BaseSupplier::find()
- ->select(['DISTINCT(a.ID)', 'a.SUPPLIER_NAME', 'c.seq', 'c.id as seq_id'])
- ->joinWith('baseSupplierSale as b')
- ->leftJoin('opera_sort c', 'a.ID=c.channel_id')
- ->from('base_supplier as a')
- ->where(['b.PARENT_TYPE' => 25, 'a.SUPPLIER_TYPE' => 301, 'a.cancel_flag' => 0, 'a.IS_DISABLED' => 0, 'b.cancel_flag' => 0, 'a.MAIN_CORP_ID' => 1])
- ->orderBy('`c`.`seq` is null, c.seq ASC, a.ID ASC')
- // ->createCommand()->getRawSql();
- ->asArray()->all();
-
- return $res;
- }
-
- // 查询所有直连渠道的信息 -- 用于酒店直连渠道查询
- public function getConnectChannel($channel_arr)
- {
- $res = BaseSupplier::find()
- ->select(['ID', 'SUPPLIER_NAME'])
- ->where(['ID' => $channel_arr, 'CANCEL_FLAG' => 0, 'SUPPLIER_TYPE' => 301])->asArray()->all();
-
- return $res;
- }
-
- /**
- * 获取第一个供应商
- * @return array|ActiveRecord[]
- */
- public function getFirstSupplier()
- {
- $res = BaseSupplier::find()
- ->select(['a.ID', 'a.SUPPLIER_NAME'])
- ->innerJoinWith('baseSupplierPurchase as b')
- ->from('base_supplier as a')
- ->where(['b.PRODUCT_TYPE' => 25, 'a.SUPPLIER_TYPE' => 187, 'a.cancel_flag' => 0, 'b.cancel_flag' => 0, 'a.MAIN_CORP_ID' => 1])
- ->groupBy('b.SUPPLIER_ID')
- ->limit(1)->asArray()->all();
-
- return $res;
- }
-
- /**
- * Function Description:获取车队列表
- * Function Name: getBusTeamList
- *
- * @return array|ActiveRecord[]
- *
- * @author 李健
- */
- public function getBusTeamList()
- {
- $select = [
- 's.id as supplier_id',
- 's.supplier_name as bus_team',
- ];
- $where = ['and'];
- $where[] = ['=', 's.cancel_flag', '0'];
- $where[] = ['=', 's.supplier_type', '187'];
- $where[] = ['=', 'p.cancel_flag', '0'];
- $where[] = ['=', 'p.product_type', '259'];
- $res = self::find()
- ->select($select)
- ->from(self::tableName() . ' s')
- ->innerJoin(BaseSupplierPurchase::tableName() . ' p', 's.id = p.supplier_id')
- ->where($where)
- ->groupBy('s.id')
- ->asArray()
- ->all();
-
- return $res;
- }
-
- /**
- * Function Description:根据渠道号获取渠道结算方式
- * Function Name: getSettType
- * @param $id
- *
- * @return mixed
- *
- * @author 娄梦宁
- */
- public function getSettType($id)
- {
- $result = self::find()->select('sett_type')->from(self::tableName())->where(['id' => $id])->asArray()->one();
-
- return $result['sett_type'];
- }
-
- }
|