Supply.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. namespace app\worker\controller;
  3. use app\worker\BaseController;
  4. use app\common\model\Worker as WorkerModel;
  5. use app\common\model\Supply as SupplyModel;
  6. use app\common\validate\Supply as SupplyValidate;
  7. use think\exception\ValidateException;
  8. use think\facade\Session;
  9. use think\facade\Db;
  10. use think\facade\Request;
  11. class Supply extends BaseController
  12. {
  13. // 企业招聘
  14. public function supplyList()
  15. {
  16. $access_worker = Session::get('access_worker');
  17. $is_released = 1;
  18. if($access_worker['status'] == 1)
  19. {
  20. $is_released = is_released($access_worker['id']);
  21. }
  22. return view('supply/supplylist',[
  23. 'is_released' => $is_released['code']
  24. ]);
  25. }
  26. public function supplyForm()
  27. {
  28. $id = input('id/d, 0');
  29. $supply = SupplyModel::findOrEmpty($id);
  30. $access_worker = Session::get('access_worker');
  31. $provincelist = array(
  32. ['value'=>"全国", 'title'=>"全国"],
  33. ['value'=>"北京市", 'title'=>"北京市"],
  34. ['value'=>"天津市", 'title'=>"天津市"],
  35. ['value'=>"河北省", 'title'=>"河北省"],
  36. ['value'=>"山西省", 'title'=>"山西省"],
  37. ['value'=>"内蒙古自治区", 'title'=>"内蒙古自治区"],
  38. ['value'=>"辽宁省", 'title'=>"辽宁省"],
  39. ['value'=>"吉林省", 'title'=>"吉林省"],
  40. ['value'=>"黑龙江省", 'title'=>"黑龙江省"],
  41. ['value'=>"上海市", 'title'=>"上海市"],
  42. ['value'=>"江苏省", 'title'=>"江苏省"],
  43. ['value'=>"浙江省", 'title'=>"浙江省"],
  44. ['value'=>"安徽省", 'title'=>"安徽省"],
  45. ['value'=>"福建省", 'title'=>"福建省"],
  46. ['value'=>"江西省", 'title'=>"江西省"],
  47. ['value'=>"山东省", 'title'=>"山东省"],
  48. ['value'=>"河南省", 'title'=>"河南省"],
  49. ['value'=>"湖北省", 'title'=>"湖北省"],
  50. ['value'=>"湖南省", 'title'=>"湖南省"],
  51. ['value'=>"广东省", 'title'=>"广东省"],
  52. ['value'=>"广西壮族自治区", 'title'=>"广西壮族自治区"],
  53. ['value'=>"海南省", 'title'=>"海南省"],
  54. ['value'=>"重庆市", 'title'=>"重庆市"],
  55. ['value'=>"四川省", 'title'=>"四川省"],
  56. ['value'=>"贵州省", 'title'=>"贵州省"],
  57. ['value'=>"云南省", 'title'=>"云南省"],
  58. ['value'=>"西藏自治区", 'title'=>"西藏自治区"],
  59. ['value'=>"陕西省", 'title'=>"陕西省"],
  60. ['value'=>"甘肃省", 'title'=>"甘肃省"],
  61. ['value'=>"青海省", 'title'=>"青海省"],
  62. ['value'=>"宁夏回族自治区", 'title'=>"宁夏回族自治区"],
  63. ['value'=>"新疆维吾尔自治区", 'title'=>"新疆维吾尔自治区"],
  64. ['value'=>"台湾省", 'title'=>"台湾省"],
  65. ['value'=>"香港特别行政区", 'title'=>"香港特别行政区"],
  66. ['value'=>"澳门特别行政区", 'title'=>"澳门特别行政区"]
  67. );
  68. return view('supply/supplyform',[
  69. 'provincelist' => $provincelist,
  70. 'title' => $access_worker['title'],
  71. 'supply' => $supply
  72. ]);
  73. }
  74. public function editSupply()
  75. {
  76. $id = input('id/d', 0);
  77. $workerid = $this->access_worker['id'];
  78. $descity = input('descity/a', []);
  79. if (in_array('全国', $descity)){
  80. $descity = ['全国'];
  81. }
  82. $data = [
  83. 'workerid' => $workerid,
  84. 'mnumber' => input('mnumber/d', 0),
  85. 'wnumber' => input('wnumber/d', 0),
  86. 'agegroup' => input('agegroup/s', ""),
  87. 'province' => input('province/s', ""),
  88. 'city' => input('city/s', ""),
  89. 'district' => input('district/s', ""),
  90. 'descity' => implode(",", $descity),
  91. 'candate' => input('candate/s', ""),
  92. 'telephone' => input('telephone/s', ""),
  93. 'remark' => input('remark/s', ""),
  94. 'status' => (int)2
  95. ];
  96. try {
  97. validate(SupplyValidate::class)->check($data);
  98. } catch (ValidateException $e) {
  99. exit(json_encode(array(
  100. 'code' => 1,
  101. 'msg' => $e->getError()
  102. )));
  103. }
  104. if (empty($id)){
  105. if($this->access_worker['status'] == 1)
  106. {
  107. $is_released = is_released($workerid);
  108. if($is_released['code'] == 1001)
  109. {
  110. return $is_released;
  111. }
  112. }
  113. $data['createtime'] = $data['updatetime'] = time();
  114. $data['telearr'] = array();
  115. $supply = SupplyModel::create($data);
  116. }else{
  117. $data['updatetime'] = time();
  118. $supply = SupplyModel::find($id);
  119. $supply->save($data);
  120. }
  121. exit(json_encode(array(
  122. 'code' => 0
  123. )));
  124. }
  125. public function editSupplyStatus()
  126. {
  127. $id = input('id/d', 0);
  128. $workerid = $this->access_worker['id'];
  129. if (Request::isAjax()){
  130. $data = [
  131. 'workerid' => $workerid,
  132. 'status' => input('status/d', 0),
  133. ];
  134. if (empty($id)){
  135. $data['createtime'] = $data['updatetime'] = time();
  136. $data['telearr'] = array();
  137. $supply = SupplyModel::create($data);
  138. }else{
  139. $data['updatetime'] = time();
  140. Db::name('supply')->where(['workerid'=>$workerid,'id'=>$id])->update($data);
  141. }
  142. exit(json_encode(array(
  143. 'code' => 0
  144. )));
  145. }else{
  146. $data = Db::name('supply')
  147. ->field('a.id,a.status,b.title')
  148. ->alias('a')
  149. ->where('a.workerid',$workerid)
  150. ->where('a.id',$id)
  151. ->join('worker b','a.workerid = b.id','LEFT')
  152. ->find();
  153. if($data['status'] == 2){
  154. $data['status_text'] = '待审核';
  155. }elseif($data['status'] == 3){
  156. $data['status_text'] = '已上架';
  157. }elseif($data['status'] == 4){
  158. $data['status_text'] = '已停招';
  159. }elseif($data['status'] == 5){
  160. $data['status_text'] = '已下架';
  161. }
  162. return view('supply/editsupplystatus',[
  163. 'data' => $data
  164. ]);
  165. }
  166. }
  167. public function fieldSupply()
  168. {
  169. $id = input('id/d',0);
  170. $supply = SupplyModel::findOrEmpty($id);
  171. $supply->save([
  172. 'telephone'=> input('value/s', "")
  173. ]);
  174. exit(json_encode(array(
  175. 'code' => 0
  176. )));
  177. }
  178. public function delSupply()
  179. {
  180. $idarr = input('idarr/a');
  181. $workerid = $this->access_worker['id'];
  182. $result = Db::name('supply')
  183. ->where('workerid',$workerid)
  184. ->whereIn('id',$idarr)
  185. ->update(['status'=>(int)6]);
  186. if ($result){
  187. exit(json_encode(array(
  188. 'code' => 0,
  189. 'msg' => ""
  190. )));
  191. }
  192. exit(json_encode(array(
  193. 'code' => 1,
  194. 'msg' => "删除失败,请稍后重试"
  195. )));
  196. }
  197. public function listSupply()
  198. {
  199. $limit = input('limit/d',20);
  200. $page = input('page/d',1);
  201. $map = array();
  202. $keywords = input('keywords/s', "");
  203. $workerid = $this->access_worker['id'];
  204. $map[] = ['workerid', '=', $workerid];
  205. if (!empty($keywords)){
  206. $map[] =['province|city|district|descity', 'like', '%'.$keywords.'%'];
  207. }
  208. $status = input('status/d');
  209. if (!empty($status)){
  210. $map[] = ['status', '=', $status];
  211. }else{
  212. $map[] = ['status', '<', 6];
  213. }
  214. $list = SupplyModel::with(['worker'])->where($map)->order(['priority'=>'desc','id'=>'desc',])->limit($limit)->page($page)->append(['status_text'])->select();
  215. $count = SupplyModel::where($map)->count();
  216. if ($count==0){
  217. exit(json_encode(array(
  218. 'code' => 1,
  219. 'msg' => "未查询到数据"
  220. )));
  221. }
  222. exit(json_encode(array(
  223. 'code' => 0,
  224. 'msg' => "",
  225. 'count' => $count,
  226. 'data' => $list
  227. )));
  228. }
  229. }