AgentFrontBind.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use Yii;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * This is the model class for table "{{%agent_front_bind}}".
  13. *
  14. * @property integer $id
  15. * @property integer $front_agent_admin_id
  16. * @property integer $type_id
  17. * @property integer $type
  18. * @property integer $created_at
  19. * @property integer $updated_at
  20. * @property integer $is_delete
  21. * @property integer $status
  22. * @property integer $md_id
  23. */
  24. class AgentFrontBind extends \yii\db\ActiveRecord
  25. {
  26. const TYPE_SUPPLIER = 0;//供货商类型
  27. const TYPE_STORE = 1;//商家类型
  28. /**
  29. * @inheritdoc
  30. */
  31. public static function tableName()
  32. {
  33. return '{{%agent_front_bind}}';
  34. }
  35. public function behaviors()
  36. {
  37. return [
  38. [
  39. 'class' => TimestampBehavior::class,
  40. 'attributes' => [
  41. ActiveRecord::EVENT_BEFORE_INSERT => ['updated_at', 'created_at'],
  42. ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'
  43. ]
  44. ]
  45. ];
  46. }
  47. /**
  48. * @inheritdoc
  49. */
  50. public function rules()
  51. {
  52. return [
  53. [['id', 'front_agent_admin_id', 'type_id', 'type', 'created_at', 'updated_at', 'is_delete', 'status', 'md_id'], 'integer']
  54. ];
  55. }
  56. public static function getStoreBindFrontAgent($store_id) {
  57. return self::find()->alias('agb')->leftJoin(['a' => Admin::tableName()], 'agb.front_agent_admin_id = a.id')
  58. ->where(['agb.type' => self::TYPE_STORE, 'agb.type_id' => $store_id, 'agb.is_delete' => 0, 'agb.status' => 1])
  59. ->select('a.id front_agent_admin_id, a.name')->groupBy('a.id')->asArray()->all();
  60. }
  61. //获取仓库绑定的供货商
  62. public static function getAgentFrontBindSupplierId($front_agent_admin_id) {
  63. return self::find()->alias('a')
  64. ->leftJoin(['s' => Supplier::tableName()], 'a.type_id = s.id AND a.type = ' . self::TYPE_SUPPLIER)
  65. ->where([
  66. 'a.type' => self::TYPE_SUPPLIER,
  67. 'a.is_delete' => 0,
  68. 'a.status' => 1,
  69. 's.is_delete' => 0,
  70. 'a.front_agent_admin_id' => $front_agent_admin_id
  71. ])
  72. ->groupBy('s.cloud_supplier_id')
  73. ->select('s.cloud_supplier_id')->column();
  74. }
  75. }