HouseKeepingController.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /**
  3. * Created by north.Deng's MAC
  4. * User: north.Deng
  5. * Date: 2018/1/9
  6. * Time: 上午10:02
  7. * description :
  8. */
  9. class HouseKeepingController extends JBaseController
  10. {
  11. public function actionList()
  12. {
  13. $id = (Yii::app()->request->getParam('id'));
  14. $store_id = Yii::app()->request->getParam('store_id','');
  15. $criteria = new EMongoCriteria();
  16. if (!empty($store_id)) {
  17. $criteria->store_id('==', intval($store_id));
  18. }
  19. // id筛选
  20. if (!empty($id)) {
  21. $criteria->user_id('==', $id);
  22. }
  23. $criteria->sort('time',EMongoCriteria::SORT_DESC);
  24. $cursor = HouseKeeping::model()->findAll($criteria);
  25. $rows = CommonFn::getRowsFromCursor($cursor);
  26. $parsedRows = HouseKeeping::model()->parse($rows);
  27. $total = $cursor->count();
  28. echo CommonFn::composeDatagridData($parsedRows, $total);
  29. }
  30. public function actionGetUser()
  31. {
  32. $id = (Yii::app()->request->getParam('user_id'));
  33. $c= new EMongoCriteria();
  34. $c->user_id('==',new MongoId($id));
  35. $tmp = JEmploye::model()->find($c);
  36. $data = array();
  37. if (empty($tmp) ) {
  38. $data['user_id'] = '';
  39. $data['store_id'] = '';
  40. echo json_encode($data);exit;
  41. }
  42. $data['user_id'] = $tmp->user_id;
  43. $data['store_id'] = $tmp->owned_stores;
  44. echo json_encode($data);
  45. }
  46. public function actionGetStore()
  47. {
  48. $c= new EMongoCriteria();
  49. $c->status('==',2);
  50. $tmp = Store::model()->findAll($c);
  51. $i = 0;
  52. $data = array();
  53. foreach ($tmp as $k => $v) {
  54. $data[$i]['store_id'] = $v->store_id;
  55. $data[$i]['store_name'] = $v->store_name;
  56. $data[$i]['mobile'] = $v->mobile;
  57. $data[$i++]['address'] = $v->address;
  58. }
  59. echo json_encode($data);
  60. }
  61. public function actionEdit()
  62. {
  63. $status = intval(Yii::app()->request->getParam('status', ''));
  64. $contract = intval(Yii::app()->request->getParam('contract', ''));
  65. $type = intval(Yii::app()->request->getParam('type', ''));
  66. $cart = intval(Yii::app()->request->getParam('cart', ''));
  67. $skill = Yii::app()->request->getParam('skill', '');
  68. $age = intval(Yii::app()->request->getParam('age', 0));
  69. $tech = (Yii::app()->request->getParam('tech', ''));
  70. $desc = (Yii::app()->request->getParam('desc', ''));
  71. $yc_time = intval(Yii::app()->request->getParam('yc_time', ''));
  72. $server_start_time = intval(Yii::app()->request->getParam('server_start_time', ''));
  73. $status_time = intval(Yii::app()->request->getParam('status_time', ''));
  74. $server_end_time = intval(Yii::app()->request->getParam('server_end_time', ''));
  75. $id = Yii::app()->request->getParam('id');
  76. if (!CommonFn::isMongoId($id)) {
  77. CommonFn::requestAjax(false, '修改失败', array());
  78. }
  79. $h = HouseKeeping::get(new MongoId($id));
  80. if (!empty($contract)) {
  81. $h->contract = $contract;
  82. }
  83. if (!empty($type)) {
  84. $h->type = $type;
  85. }
  86. if (!empty($cart)) {
  87. $h->cart = $cart;
  88. }
  89. if (!empty($skill)) {
  90. $h->skill = $skill;
  91. }
  92. if (!empty($age)) {
  93. $h->age = $age;
  94. }
  95. if (!empty($desc)) {
  96. $h->desc = $desc;
  97. }
  98. if (!empty($status)) {
  99. $h->status = $status;
  100. }
  101. if (!empty($status_time)) {
  102. $h->status_time = $status_time;
  103. }
  104. if (!empty($server_start_time)) {
  105. $h->server_start_time = $server_start_time;
  106. }
  107. if (!empty($server_end_time)) {
  108. $h->server_end_time = $server_end_time;
  109. }
  110. if (!empty($yc_time)) {
  111. $h->yc_time = $yc_time;
  112. }
  113. if (!empty($tech)) {
  114. $h->tech = $tech;
  115. }
  116. $success = $h->save();
  117. CommonFn::requestAjax($success, '修改成功', array());
  118. }
  119. public function actionAdd()
  120. {
  121. $mobile = (Yii::app()->request->getParam('mobile', ''));
  122. $user_name = (Yii::app()->request->getParam('user_name', ''));
  123. $user_id = (Yii::app()->request->getParam('user_id', ''));
  124. $type = intval(Yii::app()->request->getParam('type', 1));
  125. $cart = intval(Yii::app()->request->getParam('cart', 1));
  126. $skill = json_decode(Yii::app()->request->getParam('skill'));
  127. $age = intval(Yii::app()->request->getParam('age', 1));
  128. $address = Yii::app()->request->getParam('address', '');
  129. $tech = (Yii::app()->request->getParam('tech', ''));
  130. $desc = (Yii::app()->request->getParam('desc', ''));
  131. $yc_time = intval(Yii::app()->request->getParam('yc_time', ''));
  132. $server_start_time = intval(Yii::app()->request->getParam('server_start_time', ''));
  133. $status_time = intval(Yii::app()->request->getParam('status_time', ''));
  134. $server_end_time = intval(Yii::app()->request->getParam('server_end_time', ''));
  135. $store_id = intval(Yii::app()->request->getParam('store_id', ''));
  136. $h = new HouseKeeping();
  137. $h->store_id = $store_id;
  138. $h->user_name = $user_name;
  139. $h->user_id = $user_id;
  140. $h->mobile = $mobile;
  141. $h->type = $type;
  142. $h->cart = $cart;
  143. $h->address = $address;
  144. $h->server_start_time = $server_start_time;
  145. $h->server_end_time = $server_end_time;
  146. $h->skill = $skill;
  147. $h->yc_time = $yc_time;
  148. $h->age = $age;
  149. $h->desc = $desc;
  150. $h->status = 1;
  151. $h->status_time = $status_time;
  152. $h->tech = $tech;
  153. $h->contract = 1;
  154. $h->time = time();
  155. $result = $h->save();
  156. if ($result) {
  157. CommonFn::requestAjax($result, '添加成功', array());
  158. } else {
  159. CommonFn::requestAjax($result, '添加失败', array());
  160. }
  161. }
  162. public function actionAddUserInfo()
  163. {
  164. $user_id = Yii::app()->request->getParam('user_id','');
  165. if (empty($user_id) || !CommonFn::isMongoId($user_id)) {
  166. CommonFn::requestAjax(false, '添加失败1', array());
  167. }
  168. $mobile = Yii::app()->request->getParam('mobile','');
  169. $name = Yii::app()->request->getParam('name','');
  170. $user = RUser::get(new MongoId($user_id));
  171. $user->user_info = array('mobile' => $mobile,'name' => $name);
  172. if ($user->save()) {
  173. CommonFn::requestAjax(true, '添加成功', array());
  174. } else {
  175. CommonFn::requestAjax(false, '添加失败', array());
  176. }
  177. }
  178. }