Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

186 lignes
6.1 KiB

  1. <?php
  2. namespace backend\modules\api\models;
  3. use Yii;
  4. use yii\data\ActiveDataProvider;
  5. use yii\helpers\ArrayHelper;
  6. /**
  7. * This is the model class for table "opera_tailor_product".
  8. *
  9. * @property integer $id
  10. * @property integer $cancel_flag
  11. * @property string $create_time
  12. * @property string $update_time
  13. * @property integer $create_user_id
  14. * @property integer $update_user_id
  15. * @property integer $main_corp_id
  16. * @property string $tailor_product_name
  17. * @property string $tailor_product_code
  18. * @property integer $supplier_id
  19. * @property integer $prod_type
  20. * @property integer $is_onsale
  21. * @property string $product_price
  22. * @property string $cost_price
  23. * @property string $memo
  24. */
  25. class OperaTailorProduct extends \yii\db\ActiveRecord
  26. {
  27. public $res_arr;
  28. public $tp_res_select;
  29. const PROD_TYPE_ARR = [701 => '全城接', 702 => '全城送'];
  30. const TAILOR_TYPE_PARENT = 700;
  31. /**
  32. * @inheritdoc
  33. */
  34. public static function tableName()
  35. {
  36. return 'opera_tailor_product';
  37. }
  38. /**
  39. * @inheritdoc
  40. */
  41. public function rules()
  42. {
  43. return [
  44. [['cancel_flag', 'create_time', 'update_time', 'create_user_id', 'update_user_id', 'main_corp_id', 'tailor_product_name', 'tailor_product_code', 'supplier_id', 'prod_type', 'is_onsale', 'product_price', 'cost_price', 'memo'], 'required'],
  45. [['cancel_flag', 'create_user_id', 'update_user_id', 'main_corp_id', 'supplier_id', 'prod_type', 'is_onsale'], 'integer'],
  46. [['product_price', 'cost_price'], 'number'],
  47. [['create_time'], 'string', 'max' => 20],
  48. [['tailor_product_name', 'tailor_product_code'], 'string', 'max' => 50],
  49. [['memo'], 'string', 'max' => 200],
  50. ];
  51. }
  52. /**
  53. * @inheritdoc
  54. */
  55. public function attributeLabels()
  56. {
  57. return [
  58. 'id' => '动态产品id',
  59. 'cancel_flag' => 'Cancel Flag',
  60. 'create_time' => 'Create Time',
  61. 'update_time' => 'Update Time',
  62. 'create_user_id' => 'Create User ID',
  63. 'update_user_id' => 'Update User ID',
  64. 'main_corp_id' => '运营主体id',
  65. 'tailor_product_name' => '动态产品名称',
  66. 'tailor_product_code' => '动态产品编号',
  67. 'supplier_id' => '产品供应商id',
  68. 'prod_type' => '产品类型',
  69. 'is_onsale' => '产品上下架 0为下架 1为上架',
  70. 'product_price' => '产品售价',
  71. 'cost_price' => '产品成本价',
  72. 'memo' => '产品备注',
  73. 'tp_res_select' => '选择站点',
  74. ];
  75. }
  76. /**
  77. * Function Description:获取站点列表
  78. * Function Name: getIndex
  79. *
  80. *
  81. * @author LUOCJ
  82. */
  83. public function getIndex($data)
  84. {
  85. $query = self::find()->where(['and', ['=', 'cancel_flag', 0]]);
  86. $dataProvider = new ActiveDataProvider([
  87. 'query' => $query,
  88. ]);
  89. if (isset($data['product_name']))
  90. $query->andFilterWhere(['like', 'tailor_product_name', $data['product_name']]);
  91. if (isset($data['product_code']))
  92. $query->andFilterWhere(['like', 'tailor_product_code', $data['product_code']]);
  93. if (isset($data['is_onsale']) && $data['is_onsale'] != -1)
  94. $query->andFilterWhere(['=', 'is_onsale', $data['is_onsale']]);
  95. return $dataProvider;
  96. }
  97. /**
  98. * @param $id_str
  99. *
  100. * @return bool
  101. *
  102. * 组合产品上架控制 $id_str:1, 1,2,3, $op: up 上架 down 下架 delete 删除
  103. */
  104. public static function isOnSaleControl($id_str, $op)
  105. {
  106. if ($op == 'up') {
  107. $change_value = 1;
  108. $change_attr = 'is_onsale';
  109. } elseif ($op == 'down') {
  110. $change_value = 0;
  111. $change_attr = 'is_onsale';
  112. } elseif ($op == 'delete') {
  113. $change_value = 1;
  114. $change_attr = 'cancel_flag';
  115. } else {
  116. return $data['code'] = 1;
  117. }
  118. $id_str = substr($id_str, 0, -1);
  119. $id_arr = explode(',', $id_str);
  120. $result = Yii::$app->db
  121. ->createCommand("update opera_tailor_product set opera_tailor_product.$change_attr = :change_value where opera_tailor_product.id = :id_arr")
  122. ->bindValues([':change_value' => $change_value, ':id_arr' => $id_str])
  123. ->execute();
  124. if (!$result || $result <= 0)
  125. return $data['code'] = 1;
  126. else
  127. return $data['code'] = 0;
  128. }
  129. /**
  130. * Function Description:获取动态产品列表
  131. * Function Name: getTailorType
  132. *
  133. * @return array
  134. *
  135. * @author LUOCJ
  136. */
  137. public static function getProduct($prod_type)
  138. {
  139. $data = self::find()->select(['id', 'tailor_product_name'])->where(['cancel_flag' => 0, 'is_onsale' => 1, 'prod_type' => $prod_type])->asArray()->all();
  140. $result = ArrayHelper::map($data, 'id', 'tailor_product_name');
  141. return ['' => '请选择'] + $result;
  142. }
  143. /**
  144. * Function Description:获取动态产品站点列表
  145. * Function Name: getStation
  146. *
  147. * @return array
  148. *
  149. * @author LUOCJ
  150. */
  151. public static function getStation($product_id)
  152. {
  153. $data = OperaTailorProductStation::find()->select(['base_resource.res_id', 'base_resource.res_name'])->innerJoin('base_resource', 'base_resource.res_id = opera_tailor_product_station.res_id')->where(['opera_tailor_product_station.cancel_flag' => 0, 'opera_tailor_product_station.product_id' => $product_id])->asArray()->all();
  154. $result = ArrayHelper::map($data, 'res_id', 'res_name');
  155. return ['' => '请选择'] + $result;
  156. }
  157. /**
  158. * Function Description:获取动态产品类型列表
  159. * Function Name: getTailorType
  160. *
  161. * @return array
  162. *
  163. * @author LUOCJ
  164. */
  165. public static function getTailorType()
  166. {
  167. $data = DictType::find()->select(['id', 'type_name'])->where(['parent_id' => self::TAILOR_TYPE_PARENT])->asArray()->all();
  168. $result = ArrayHelper::map($data, 'id', 'type_name');
  169. return ['' => '请选择'] + $result;
  170. }
  171. }