Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

217 rader
6.6 KiB

  1. <?php
  2. namespace backend\modules\zzcs\controllers;
  3. use backend\modules\zzcs\models\BaseSupplier;
  4. use Yii;
  5. use yii\web\Controller;
  6. use backend\modules\zzcs\models\BaseBus;
  7. use backend\modules\zzcs\models\BaseResource;
  8. use backend\modules\zzcs\models\DictType;
  9. use common\models\zzcsUtils;
  10. use yii\base\Exception;
  11. class BaseController extends Controller
  12. {
  13. public $enableCsrfValidation = false;
  14. public $layout = '@backend/modules/zzcs/views/layouts/zzcs';
  15. /**
  16. * Function Description:
  17. * Function Name: actionIndex
  18. *
  19. * @return string
  20. *
  21. * @author 温依莅
  22. */
  23. public function actionIndex()
  24. {
  25. return $this->render('index');
  26. }
  27. /**
  28. * Function Description:品牌列表
  29. * Function Name: actionList
  30. *
  31. * @return string
  32. *
  33. * @author 温依莅
  34. */
  35. public function actionBrandList()
  36. {
  37. \Yii::$app->view->title = '品牌管理';
  38. //品牌列表
  39. $brand_list = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 134, 'cancel_flag' => 0])->asArray()->orderBy(['update_time' => SORT_DESC])->all();
  40. return $this->render('brand-list', ['brandList' => $brand_list]);
  41. }
  42. /**
  43. * Function Description:品牌增加
  44. * Function Name: actionBrandAdd
  45. *
  46. * @return string
  47. *
  48. * @author 温依莅
  49. */
  50. public function actionBrandAdd()
  51. {
  52. $request = Yii::$app->request;
  53. $user_id=$request->cookies->getValue('user_id',0);
  54. $res_name = $request->post('res_name', '');
  55. if ($res_name == '') {
  56. $json["code"] = '1';
  57. $json["info"] = '品牌名不能为空';
  58. return json_encode($json);
  59. }
  60. try {
  61. //1判断是否存在res_name相同的选项,如果存在
  62. $brand = BaseResource::find()->where(['res_type_id' => 134, 'res_name' => $res_name])->one();
  63. if (!is_null($brand)) {
  64. #1.1如果cancel_flag为0,则返回提示,已有该品牌
  65. if ($brand->CANCEL_FLAG == 0) {
  66. $json["code"] = '1';
  67. $json["info"] = '已有该品牌,请勿重复提交';
  68. return json_encode($json);
  69. } else if ($brand->CANCEL_FLAG == 1) {
  70. #1.2如果cancel_flag为1,则将该res_name的cancel_flag置为0
  71. $brand->CANCEL_FLAG=0;
  72. $brand->UPDATE_TIME=date('Y-m-d H:i:s', time());
  73. $brand->UPDATE_USER_ID=$user_id;
  74. if(!$brand->update()){
  75. throw new Exception($brand->getErrors());
  76. }
  77. }
  78. } else {
  79. //2若不存在res_name相同的选项,则插入新数据
  80. #目前最大的res_id值,加1
  81. $new_res_id=BaseResource::find()->max('res_id')+1;
  82. $values= [
  83. 'RES_ID' => $new_res_id,
  84. 'RES_NAME' => $res_name,
  85. 'CREATE_USER_ID' => $user_id,
  86. 'CANCEL_FLAG' => 0,
  87. 'RES_TYPE_ID' => 134,
  88. 'CREATE_TIME' => date('Y-m-d H:i:s', time()),
  89. 'UPDATE_TIME' => date('Y-m-d H:i:s', time()),
  90. ];
  91. $new_brand=new BaseResource;
  92. $new_brand->attributes = $values;
  93. if(!$new_brand->insert()){
  94. throw new Exception($new_brand->getErrors());
  95. }
  96. }
  97. } catch (\Exception $e) {
  98. $json["code"] = '1';
  99. $json["info"] = '品牌增加失败';
  100. $json["error_info"] = $e->getMessage();
  101. return json_encode($json);
  102. }
  103. $json["code"] = '0';
  104. $json["info"] = '品牌添加成功';
  105. return json_encode($json);
  106. }
  107. /**
  108. * Function Description:品牌删除
  109. * Function Name: actionBrandDelete
  110. *
  111. * @return string
  112. *
  113. * @author 温依莅
  114. */
  115. public function actionBrandDelete()
  116. {
  117. $request = Yii::$app->request;
  118. $res_id= $request->post('res_id', '');
  119. $brand = new BaseResource();
  120. $res = $brand->baseDeleteBrand($res_id);
  121. return json_encode($res);
  122. }
  123. /**
  124. * Function Description:品牌修改
  125. * Function Name: actionBrandAdd
  126. *
  127. * @return string
  128. *
  129. * @author 温依莅
  130. */
  131. public function actionBrandModify()
  132. {
  133. $request = Yii::$app->request;
  134. $res_id= $request->post('res_id', '');
  135. $res_name = $request->post('res_name', '');
  136. $brand = new BaseResource();
  137. $res = $brand->baseUpdateBrand($res_id,$res_name);
  138. return json_encode($res);
  139. }
  140. /**
  141. * Function Description:车型增加
  142. * Function Name: actionCarSortAdd
  143. *
  144. * @return string
  145. *
  146. * @author 温依莅
  147. */
  148. public function actionCarSortAdd(){
  149. $request = Yii::$app->request;
  150. $car_sort_name= $request->post('car_sort_name', '');
  151. $car_seat_num = $request->post('car_seat_num', '');
  152. $car = new BaseResource();
  153. $res = $car->CarSortAdd($car_sort_name,$car_seat_num);
  154. return json_encode($res);
  155. }
  156. /**
  157. * Function Description:车型删除
  158. * Function Name: actionCarSortDelete
  159. *
  160. * @return string
  161. *
  162. * @author 温依莅
  163. */
  164. public function actionCarSortDelete()
  165. {
  166. $request = Yii::$app->request;
  167. $res_id= $request->post('res_id', '');
  168. $carSort = new BaseResource();
  169. $res = $carSort->baseDeleteCar($res_id);
  170. return json_encode($res);
  171. }
  172. /**
  173. * Function Description:车型列表
  174. * Function Name: actionCarList
  175. *
  176. * @return string
  177. *
  178. * @author 温依莅
  179. */
  180. public function actionCarList()
  181. {
  182. \Yii::$app->view->title = '车型管理';
  183. //车型列表
  184. $car_list = BaseResource::find()->select(['a.res_id', 'a.res_name','b.id','b.type_name'])->from('base_resource a')->leftJoin('dict_type as b', 'a.parent_id=b.id')->where(['a.res_type_id' => 69,'b.parent_id'=>71,'cancel_flag' => 0])->orderBy(['update_time'=>SORT_DESC])->asArray()->all();
  185. return $this->render('car-list', ['carList' => $car_list]);
  186. }
  187. /**
  188. * Function Description:获取渠道商列表
  189. * Function Name: actionGetSupplier
  190. *
  191. * @return string
  192. *
  193. * @author 娄梦宁
  194. */
  195. public function actionGetSupplierList(){
  196. $base_supplier=new BaseSupplier();
  197. $result=$base_supplier->getChannelList();
  198. return json_encode(
  199. ['code'=>0,'list'=>$result]
  200. );
  201. }
  202. }