You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

237 line
7.4 KiB

  1. <?php
  2. namespace backend\modules\api\models;
  3. use backend\modules\zzcs\models\BaseSupplierPurchase;
  4. use backend\modules\zzcs\models\BaseSupplierSale;
  5. use yii\db\ActiveRecord;
  6. use yii\data\ActiveDataProvider;
  7. use Yii;
  8. /**
  9. * This is the model class for table "base_supplier".
  10. *
  11. * @property integer $ID
  12. * @property integer $MAIN_CORP_ID
  13. * @property integer $CREATE_USER_ID
  14. * @property string $CREATE_TIME
  15. * @property integer $UPDATE_USER_ID
  16. * @property string $UPDATE_TIME
  17. * @property integer $CANCEL_FLAG
  18. * @property integer $AREA_ID
  19. * @property integer $SUPPLIER_TYPE
  20. * @property string $SUPPLIER_NAME
  21. * @property string $SUPPLIER_CODE
  22. * @property integer $MANAGE_TYPE
  23. * @property string $COMPANY_NAME
  24. * @property string $ID_CARD
  25. * @property integer $IS_DISABLED
  26. * @property integer $SETT_TYPE
  27. * @property integer $SETT_FREQUENCY
  28. * @property string $ACCOUNT_BANK
  29. * @property string $ACCOUNT_NUM
  30. * @property string $ACCOUNT_NAME
  31. * @property string $SALES_MAN
  32. */
  33. class BaseSupplier extends ActiveRecord
  34. {
  35. public $product_type;
  36. public $status;
  37. /**
  38. * @inheritdoc
  39. */
  40. public static function tableName()
  41. {
  42. return 'base_supplier';
  43. }
  44. /**
  45. * @inheritdoc
  46. */
  47. public function rules()
  48. {
  49. return [
  50. [['MAIN_CORP_ID', 'CREATE_USER_ID', 'UPDATE_USER_ID', 'CANCEL_FLAG', 'AREA_ID', 'SUPPLIER_TYPE', 'MANAGE_TYPE', 'IS_DISABLED', 'SETT_TYPE', 'SETT_FREQUENCY'], 'integer'],
  51. [['CREATE_TIME', 'SUPPLIER_TYPE', 'SUPPLIER_NAME'], 'required'],
  52. [['UPDATE_TIME'], 'safe'],
  53. [['CREATE_TIME', 'ID_CARD', 'ACCOUNT_NUM'], 'string', 'max' => 20],
  54. [['SUPPLIER_NAME', 'SUPPLIER_CODE', 'COMPANY_NAME', 'ACCOUNT_BANK', 'ACCOUNT_NAME'], 'string', 'max' => 100],
  55. [['SALES_MAN'], 'string', 'max' => 30],
  56. ];
  57. }
  58. /**
  59. * @inheritdoc
  60. */
  61. public function attributeLabels()
  62. {
  63. return [
  64. 'ID' => 'ID',
  65. 'MAIN_CORP_ID' => '运营主体ID',
  66. 'CREATE_USER_ID' => '记录创建用户ID',
  67. 'CREATE_TIME' => '记录创建时间',
  68. 'UPDATE_USER_ID' => '记录最后更新用户ID',
  69. 'UPDATE_TIME' => '记录最后更新时间',
  70. 'CANCEL_FLAG' => '记录有效性标记,CANCEL_FLAG=0记录有效;CANCEL_FLAG=1,记录已删除',
  71. 'AREA_ID' => '所属区域',
  72. 'SUPPLIER_TYPE' => '供应商或渠道商标志 187:供应商 ',
  73. 'SUPPLIER_NAME' => '供应商或渠道商名称',
  74. 'SUPPLIER_CODE' => '代码',
  75. 'MANAGE_TYPE' => '经营性质 1:公司 2:个人',
  76. 'COMPANY_NAME' => '公司名称',
  77. 'ID_CARD' => '身份证号',
  78. 'IS_DISABLED' => '0:正常 1:停用',
  79. 'SETT_TYPE' => '结算方式,对应DICT_TYPE.ID',
  80. 'SETT_FREQUENCY' => '结算周期,对应DICT_TYPE.ID',
  81. 'ACCOUNT_BANK' => '开户银行',
  82. 'ACCOUNT_NUM' => '银行账号',
  83. 'ACCOUNT_NAME' => '账号名称 PRIMARY KEY (`ID`)',
  84. 'SALES_MAN' => 'Sales Man',
  85. ];
  86. }
  87. public function getdepart_status()
  88. {
  89. return $this->hasOne(DictType::className(), ['ID' => 'STATUS']);
  90. }
  91. public function getBaseSupplierPurchase()
  92. {
  93. return $this->hasMany(BaseSupplierPurchase::className(), ['SUPPLIER_ID' => 'ID']);
  94. }
  95. public function getBaseSupplierSale()
  96. {
  97. return $this->hasMany(BaseSupplierSale::className(), ['SUPPLIER_ID' => 'ID']);
  98. }
  99. /**
  100. * 获取供应商列表
  101. */
  102. public function getSupplierList()
  103. {
  104. $res = BaseSupplier::find()
  105. ->select(['a.ID', 'a.SUPPLIER_NAME'])
  106. ->innerJoinWith('baseSupplierPurchase as b')
  107. ->from('base_supplier as a')
  108. ->where(['b.PRODUCT_TYPE' => 25, 'a.SUPPLIER_TYPE' => 187, 'a.cancel_flag' => 0, 'b.cancel_flag' => 0, 'a.MAIN_CORP_ID' => 1])
  109. ->groupBy('b.SUPPLIER_ID')->asArray()->all();
  110. return $res;
  111. }
  112. /**
  113. * @Author wanglg
  114. * @Desc 获取渠道商列表
  115. *
  116. */
  117. public function getChannelList()
  118. {
  119. $res = BaseSupplier::find()
  120. ->select(['DISTINCT(a.ID)', 'a.SUPPLIER_NAME'])
  121. ->joinWith('baseSupplierSale as b')
  122. ->from('base_supplier as a')
  123. ->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])
  124. // ->createCommand() -> getRawSql();
  125. ->asArray()->all();
  126. return $res;
  127. }
  128. /**
  129. * @Author wanglg
  130. * @Desc 获取排序的渠道商列表
  131. * @return array|ActiveRecord[]
  132. */
  133. public function getOrderChannelList()
  134. {
  135. $res = BaseSupplier::find()
  136. ->select(['DISTINCT(a.ID)', 'a.SUPPLIER_NAME', 'c.seq', 'c.id as seq_id'])
  137. ->joinWith('baseSupplierSale as b')
  138. ->leftJoin('opera_sort c', 'a.ID=c.channel_id')
  139. ->from('base_supplier as a')
  140. ->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])
  141. ->orderBy('`c`.`seq` is null, c.seq ASC, a.ID ASC')
  142. // ->createCommand()->getRawSql();
  143. ->asArray()->all();
  144. return $res;
  145. }
  146. // 查询所有直连渠道的信息 -- 用于酒店直连渠道查询
  147. public function getConnectChannel($channel_arr)
  148. {
  149. $res = BaseSupplier::find()
  150. ->select(['ID', 'SUPPLIER_NAME'])
  151. ->where(['ID' => $channel_arr, 'CANCEL_FLAG' => 0, 'SUPPLIER_TYPE' => 301])->asArray()->all();
  152. return $res;
  153. }
  154. /**
  155. * 获取第一个供应商
  156. * @return array|ActiveRecord[]
  157. */
  158. public function getFirstSupplier()
  159. {
  160. $res = BaseSupplier::find()
  161. ->select(['a.ID', 'a.SUPPLIER_NAME'])
  162. ->innerJoinWith('baseSupplierPurchase as b')
  163. ->from('base_supplier as a')
  164. ->where(['b.PRODUCT_TYPE' => 25, 'a.SUPPLIER_TYPE' => 187, 'a.cancel_flag' => 0, 'b.cancel_flag' => 0, 'a.MAIN_CORP_ID' => 1])
  165. ->groupBy('b.SUPPLIER_ID')
  166. ->limit(1)->asArray()->all();
  167. return $res;
  168. }
  169. /**
  170. * Function Description:获取车队列表
  171. * Function Name: getBusTeamList
  172. *
  173. * @return array|ActiveRecord[]
  174. *
  175. * @author 李健
  176. */
  177. public function getBusTeamList()
  178. {
  179. $select = [
  180. 's.id as supplier_id',
  181. 's.supplier_name as bus_team',
  182. ];
  183. $where = ['and'];
  184. $where[] = ['=', 's.cancel_flag', '0'];
  185. $where[] = ['=', 's.supplier_type', '187'];
  186. $where[] = ['=', 'p.cancel_flag', '0'];
  187. $where[] = ['=', 'p.product_type', '259'];
  188. $res = self::find()
  189. ->select($select)
  190. ->from(self::tableName() . ' s')
  191. ->innerJoin(BaseSupplierPurchase::tableName() . ' p', 's.id = p.supplier_id')
  192. ->where($where)
  193. ->groupBy('s.id')
  194. ->asArray()
  195. ->all();
  196. return $res;
  197. }
  198. /**
  199. * Function Description:根据渠道号获取渠道结算方式
  200. * Function Name: getSettType
  201. * @param $id
  202. *
  203. * @return mixed
  204. *
  205. * @author 娄梦宁
  206. */
  207. public function getSettType($id)
  208. {
  209. $result = self::find()->select('sett_type')->from(self::tableName())->where(['id' => $id])->asArray()->one();
  210. return $result['sett_type'];
  211. }
  212. }