'全城接', 702 => '全城送']; const TAILOR_TYPE_PARENT = 700; /** * @inheritdoc */ public static function tableName() { return 'opera_tailor_product'; } /** * @inheritdoc */ public function rules() { return [ [['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'], [['cancel_flag', 'create_user_id', 'update_user_id', 'main_corp_id', 'supplier_id', 'prod_type', 'is_onsale'], 'integer'], [['product_price', 'cost_price'], 'number'], [['create_time'], 'string', 'max' => 20], [['tailor_product_name', 'tailor_product_code'], 'string', 'max' => 50], [['memo'], 'string', 'max' => 200], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => '动态产品id', 'cancel_flag' => 'Cancel Flag', 'create_time' => 'Create Time', 'update_time' => 'Update Time', 'create_user_id' => 'Create User ID', 'update_user_id' => 'Update User ID', 'main_corp_id' => '运营主体id', 'tailor_product_name' => '动态产品名称', 'tailor_product_code' => '动态产品编号', 'supplier_id' => '产品供应商id', 'prod_type' => '产品类型', 'is_onsale' => '产品上下架 0为下架 1为上架', 'product_price' => '产品售价', 'cost_price' => '产品成本价', 'memo' => '产品备注', 'tp_res_select' => '选择站点', ]; } /** * Function Description:获取站点列表 * Function Name: getIndex * * * @author LUOCJ */ public function getIndex($data) { $query = self::find()->where(['and', ['=', 'cancel_flag', 0]]); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); if (isset($data['product_name'])) $query->andFilterWhere(['like', 'tailor_product_name', $data['product_name']]); if (isset($data['product_code'])) $query->andFilterWhere(['like', 'tailor_product_code', $data['product_code']]); if (isset($data['is_onsale']) && $data['is_onsale'] != -1) $query->andFilterWhere(['=', 'is_onsale', $data['is_onsale']]); return $dataProvider; } /** * @param $id_str * * @return bool * * 组合产品上架控制 $id_str:1, 1,2,3, $op: up 上架 down 下架 delete 删除 */ public static function isOnSaleControl($id_str, $op) { if ($op == 'up') { $change_value = 1; $change_attr = 'is_onsale'; } elseif ($op == 'down') { $change_value = 0; $change_attr = 'is_onsale'; } elseif ($op == 'delete') { $change_value = 1; $change_attr = 'cancel_flag'; } else { return $data['code'] = 1; } $id_str = substr($id_str, 0, -1); $id_arr = explode(',', $id_str); $result = Yii::$app->db ->createCommand("update opera_tailor_product set opera_tailor_product.$change_attr = :change_value where opera_tailor_product.id = :id_arr") ->bindValues([':change_value' => $change_value, ':id_arr' => $id_str]) ->execute(); if (!$result || $result <= 0) return $data['code'] = 1; else return $data['code'] = 0; } /** * Function Description:获取动态产品列表 * Function Name: getTailorType * * @return array * * @author LUOCJ */ public static function getProduct($prod_type) { $data = self::find()->select(['id', 'tailor_product_name'])->where(['cancel_flag' => 0, 'is_onsale' => 1, 'prod_type' => $prod_type])->asArray()->all(); $result = ArrayHelper::map($data, 'id', 'tailor_product_name'); return ['' => '请选择'] + $result; } /** * Function Description:获取动态产品站点列表 * Function Name: getStation * * @return array * * @author LUOCJ */ public static function getStation($product_id) { $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(); $result = ArrayHelper::map($data, 'res_id', 'res_name'); return ['' => '请选择'] + $result; } /** * Function Description:获取动态产品类型列表 * Function Name: getTailorType * * @return array * * @author LUOCJ */ public static function getTailorType() { $data = DictType::find()->select(['id', 'type_name'])->where(['parent_id' => self::TAILOR_TYPE_PARENT])->asArray()->all(); $result = ArrayHelper::map($data, 'id', 'type_name'); return ['' => '请选择'] + $result; } }