BusinessController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Created by north.Deng's MAC
  4. * User: north.Deng
  5. * Date: 2018/2/28
  6. * Time: 下午12:30
  7. * description :
  8. */
  9. class BusinessController extends AdminController
  10. {
  11. public function actionIndex()
  12. {
  13. $status = CommonFn::getComboboxData(Business::$type_options, 100, true, 100);
  14. $this->render('index',[
  15. 'status' => $status
  16. ]);
  17. }
  18. public function actionList()
  19. {
  20. $pageParams = CommonFn::getPageParams();
  21. $search = Yii::app()->request->getParam('search', '');
  22. $status = intval(Yii::app()->request->getParam('status', 100));
  23. $criteria = new EMongoCriteria($pageParams);
  24. if ($status != 100 ) {
  25. $criteria->status('==',$status);
  26. }
  27. if ($search) {
  28. $criteria->addCond('source','or',new MongoRegex('/' . $search . '/'));
  29. }
  30. $cursor = Business::model()->findAll($criteria);
  31. $rows = CommonFn::getRowsFromCursor($cursor);
  32. $parsedRows = Business::model()->parse($rows);
  33. $total = $cursor->count();
  34. echo CommonFn::composeDatagridData($parsedRows, $total);
  35. }
  36. public function actionEdit()
  37. {
  38. $id = Yii::app()->request->getParam('id','');
  39. $name = Yii::app()->request->getParam('name','');
  40. $mobile = Yii::app()->request->getParam('mobile','');
  41. $type = Yii::app()->request->getParam('status','');
  42. $source = Yii::app()->request->getParam('source','');
  43. if (!CommonFn::isMongoId($id)) {
  44. CommonFn::requestAjax(false,'id错误');exit;
  45. }
  46. $business = Business::get(new MongoId($id));
  47. $business->type = (int)$type;
  48. $business->mobile = $mobile;
  49. $business->name = $name;
  50. $business->source = $source;
  51. $business->save();
  52. CommonFn::requestAjax(true,'保存成功');exit;
  53. }
  54. public function actionAdd()
  55. {
  56. $name = Yii::app()->request->getParam('name','');
  57. $mobile = Yii::app()->request->getParam('mobile','');
  58. $type = Yii::app()->request->getParam('status','');
  59. $source = Yii::app()->request->getParam('source','');
  60. $business = new Business();
  61. $business->type = (int)$type;
  62. $business->mobile = $mobile;
  63. $business->name = $name;
  64. $business->source = $source;
  65. $business->save();
  66. CommonFn::requestAjax(true,'保存成功');exit;
  67. }
  68. }