Demand.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\BaseController;
  4. use app\common\model\Worker as WorkerModel;
  5. use app\common\model\Demand as DemandModel;
  6. use app\common\model\DemandCate as DemandCateModel;
  7. use app\common\model\DemandLog as DemandLogModel;
  8. use app\common\validate\Demand as DemandValidate;
  9. use think\exception\ValidateException;
  10. use think\facade\Db;
  11. class Demand extends BaseController
  12. {
  13. // 报名记录
  14. public function logList()
  15. {
  16. $workerlist = WorkerModel::with('demand')->order(['id'=>'desc'])->select();
  17. return view('demand/loglist',[
  18. 'workerlist' => $workerlist
  19. ]);
  20. }
  21. public function delLog()
  22. {
  23. $idarr = input('idarr/a');
  24. $log = DemandLogModel::whereIn('id',$idarr)->select();
  25. $result = $log->delete();
  26. if ($result){
  27. exit(json_encode(array(
  28. 'code' => 0,
  29. 'msg' => ""
  30. )));
  31. }
  32. exit(json_encode(array(
  33. 'code' => 1,
  34. 'msg' => "删除失败,请稍后重试"
  35. )));
  36. }
  37. public function fieldLog()
  38. {
  39. $id = input('id/d',0);
  40. $log = DemandLogModel::findOrEmpty($id);
  41. if ($log->isEmpty()){
  42. exit(json_encode(array(
  43. 'code' => 1,
  44. 'msg' => "信息不存在"
  45. )));
  46. }else{
  47. $log->save([
  48. input('field/s') => input('value')
  49. ]);
  50. }
  51. exit(json_encode(array(
  52. 'code' => 0
  53. )));
  54. }
  55. public function listLog()
  56. {
  57. $limit = input('limit/d',20);
  58. $page = input('page/d',1);
  59. $map = array();
  60. $workerdemandarr = explode(",", input('workerdemand/s'));
  61. $workerid = isset($workerdemandarr[0]) ? $workerdemandarr[0] : 0;
  62. $demandid = isset($workerdemandarr[1]) ? $workerdemandarr[1] : 0;
  63. if (!empty($workerid)){
  64. $map[] = ['workerid', '=', $workerid];
  65. }
  66. if (!empty($demandid)){
  67. $map[] = ['demandid', '=', $demandid];
  68. }
  69. $list = DemandLogModel::with(['gworker','worker','demand'])->where($map)->order('id','DESC')->limit($limit)->page($page)->select();
  70. $count = DemandLogModel::where($map)->count();
  71. if ($count==0){
  72. exit(json_encode(array(
  73. 'code' => 1,
  74. 'msg' => "未查询到数据"
  75. )));
  76. }
  77. exit(json_encode(array(
  78. 'code' => 0,
  79. 'msg' => "",
  80. 'count' => $count,
  81. 'data' => $list
  82. )));
  83. }
  84. public function exportLog()
  85. {
  86. $map = array();
  87. $workerdemandarr = explode(",", input('workerdemand/s'));
  88. $workerid = isset($workerdemandarr[0]) ? $workerdemandarr[0] : 0;
  89. $demandid = isset($workerdemandarr[1]) ? $workerdemandarr[1] : 0;
  90. if (!empty($workerid)){
  91. $map[] = ['workerid', '=', $workerid];
  92. }
  93. if (!empty($demandid)){
  94. $map[] = ['demandid', '=', $demandid];
  95. }
  96. $xlsData = DemandLogModel::with(['gworker','worker','demand'])->where($map)->order('id','DESC')->select()->toArray();
  97. $xlsCell = array(
  98. array('id','表ID'),
  99. array('gworker.title','接单公司名称'),
  100. array('gworker.realname','接单公司联系人姓名'),
  101. array('gworker.mobile','接单公司联系人手机号'),
  102. array('worker.title','发单公司'),
  103. array('demand.title','订单标题'),
  104. array('createtime','接单时间'),
  105. );
  106. export_excel("接单报名记录",$xlsCell,$xlsData);
  107. }
  108. // 企业招聘
  109. public function demandList()
  110. {
  111. $workerlist = WorkerModel::order(['id'=>'desc'])->select();
  112. $catelist = DemandCateModel::order(['priority'=>'desc','id'=>'desc'])->select();
  113. return view('demand/demandlist',[
  114. 'workerlist' => $workerlist,
  115. 'catelist' => $catelist
  116. ]);
  117. }
  118. public function demandForm()
  119. {
  120. $id = input('id/d, 0');
  121. $demand = DemandModel::findOrEmpty($id);
  122. $workerlist = WorkerModel::order(['id'=>'desc'])->select();
  123. $catelist = DemandCateModel::order(['priority'=>'desc','id'=>'desc'])->select();
  124. return view('demand/demandform',[
  125. 'catelist' => $catelist,
  126. 'workerlist' => $workerlist,
  127. 'demand' => $demand
  128. ]);
  129. }
  130. public function editDemand()
  131. {
  132. $id = input('id/d', 0);
  133. $wtype = input('wtype/d', 1);
  134. $zwagall = $wtype==1 ? input('zwagall/s', "") : '';
  135. $data = [
  136. 'workerid' => input('workerid/d', 0),
  137. 'title' => input('title/s', ""),
  138. 'cateid' => input('cateid/d', 0),
  139. 'province' => input('province/s', ""),
  140. 'city' => input('city/s', ""),
  141. 'district' => input('district/s', ""),
  142. 'agegroup' => input('agegroup/s', ""),
  143. 'tags' => input('tags/a', array()),
  144. 'enddate' => input('enddate/s', ""),
  145. 'requirement' => input('requirement/s', ""),
  146. 'comdetails' => input('comdetails/s', ""),
  147. 'wtype' => $wtype,
  148. 'bwagall' => input('bwagall/s', ""),
  149. 'zwagall' => $zwagall,
  150. 'ftype' => input('ftype/d', 1),
  151. 'fwagall' => input('fwagall/s', ""),
  152. 'telephone' => input('telephone/s', ""),
  153. 'remark' => input('remark/s', ""),
  154. 'status' => input('status/d', 1),
  155. 'isfree' => input('isfree/d', 1),
  156. 'priority' => input('priority/d', 0),
  157. 'updatetime' => input('updatetime/s', ""),
  158. 'createtime' => input('createtime/s', ""),
  159. 'volume' => input('volume/d', 0)
  160. ];
  161. try {
  162. validate(DemandValidate::class)->check($data);
  163. } catch (ValidateException $e) {
  164. exit(json_encode(array(
  165. 'code' => 1,
  166. 'msg' => $e->getError()
  167. )));
  168. }
  169. if (empty($id)){
  170. $data['telearr'] = array();
  171. $data['video'] = input('new_video/s', "");
  172. $demand = DemandModel::create($data);
  173. }else{
  174. $old_video = input('old_video/s','');
  175. $new_video = input('new_video/s','');
  176. if(!empty($new_video)){
  177. $data['video'] = $new_video;
  178. }else{
  179. if(!empty($old_video))
  180. {
  181. $data['video'] = $old_video;
  182. }
  183. }
  184. $demand = DemandModel::find($id);
  185. DemandLogModel::update([ 'workerid' => input('workerid/d', 0) ],['demandid'=>$demand->id]);
  186. $demand->save($data);
  187. }
  188. exit(json_encode(array(
  189. 'code' => 0
  190. )));
  191. }
  192. public function fieldDemand()
  193. {
  194. $id = input('id/d',0);
  195. $demand = DemandModel::findOrEmpty($id);
  196. if ($demand->isEmpty()){
  197. exit(json_encode(array(
  198. 'code' => 1,
  199. 'msg' => "信息不存在"
  200. )));
  201. }else{
  202. $demand->save([
  203. input('field/s') => input('value')
  204. ]);
  205. }
  206. exit(json_encode(array(
  207. 'code' => 0
  208. )));
  209. }
  210. public function delDemand()
  211. {
  212. $idarr = input('idarr/a');
  213. DemandLogModel::whereIn('demandid',$idarr)->delete();
  214. $result = Db::name('demand')->whereIn('id',$idarr)->update(['deletetime'=>time()]);
  215. if ($result){
  216. exit(json_encode(array(
  217. 'code' => 0,
  218. 'msg' => ""
  219. )));
  220. }
  221. exit(json_encode(array(
  222. 'code' => 1,
  223. 'msg' => "删除失败,请稍后重试"
  224. )));
  225. }
  226. public function listDemand()
  227. {
  228. $limit = input('limit/d',20);
  229. $page = input('page/d',1);
  230. $map = array();
  231. $keywords = input('keywords/s', "");
  232. if (!empty($keywords)){
  233. $map[] =['title', 'like', '%'.$keywords.'%'];
  234. }
  235. $workerid = input('workerid/d', 0);
  236. if (!empty($workerid)){
  237. $map[] = ['workerid', '=', $workerid];
  238. }
  239. $cateid = input('cateid/d', 0);
  240. if (!empty($cateid)){
  241. $map[] = ['cateid', '=', $cateid];
  242. }
  243. $wtype = input('wtype/d');
  244. if (!empty($wtype)){
  245. $map[] = ['wtype', '=', $wtype];
  246. }
  247. $ftype = input('ftype/d');
  248. if (!empty($ftype)){
  249. $map[] = ['ftype', '=', $ftype];
  250. }
  251. $status = input('status/d');
  252. if (!empty($status)){
  253. $map[] = ['status', '=', $status];
  254. }
  255. $isfree = input('isfree/d',0);
  256. if (!empty($isfree)){
  257. $map[] = ['isfree', '=', $isfree];
  258. }
  259. $daterange = input('daterange/s', "");
  260. if (!empty($daterange)){
  261. $daterangearr = explode("~", $daterange);
  262. $map[] = ['createtime', '>= time', trim($daterangearr[0])];
  263. $map[] = ['createtime', '<= time', trim($daterangearr[1])];
  264. }
  265. $list = DemandModel::with(['worker','demandCate'])->withCount(['demandLog'])->where($map)->order(['priority'=>'desc','id'=>'desc',])->limit($limit)->page($page)->append(['wtype_text','ftype_text','status_text','isfree_text'])->select();
  266. $count = DemandModel::where($map)->count();
  267. if ($count==0){
  268. exit(json_encode(array(
  269. 'code' => 1,
  270. 'msg' => "未查询到数据"
  271. )));
  272. }
  273. exit(json_encode(array(
  274. 'code' => 0,
  275. 'msg' => "",
  276. 'count' => $count,
  277. 'data' => $list
  278. )));
  279. }
  280. // 岗位类型
  281. public function cateList()
  282. {
  283. return view('demand/catelist');
  284. }
  285. public function cateForm()
  286. {
  287. $id = input('id/d', 0);
  288. $cate = DemandCateModel::findOrEmpty($id);
  289. return view('demand/cateform',[
  290. 'cate' => $cate
  291. ]);
  292. }
  293. public function listCate()
  294. {
  295. $limit = input('limit');
  296. $page = input('page');
  297. $list = DemandCateModel::order(['priority'=>'desc','id'=>'desc'])->limit($limit)->page($page)->select();
  298. $count = DemandCateModel::count();
  299. if ($count==0){
  300. exit(json_encode(array(
  301. 'code' => 1,
  302. 'msg' => "未查询到数据"
  303. )));
  304. }
  305. exit(json_encode(array(
  306. 'code' => 0,
  307. 'msg' => "",
  308. 'count' => $count,
  309. 'data' => $list
  310. )));
  311. }
  312. public function fieldCate()
  313. {
  314. $id = input('id/d', 0);
  315. $info = DemandCateModel::find($id);
  316. $info->save([
  317. input('field/s') => input('value/s', "")
  318. ]);
  319. exit(json_encode(array(
  320. 'code' => 0
  321. )));
  322. }
  323. public function editCate()
  324. {
  325. $id = input('id/d');
  326. if (empty($id)){
  327. $cate = DemandCateModel::create([
  328. 'title' => input('title/s', ""),
  329. 'priority' => input('priority/d', 0)
  330. ]);
  331. }else{
  332. $cate = DemandCateModel::find($id);
  333. $cate->save([
  334. 'title' => input('title/s', ""),
  335. 'priority' => input('priority/d', 0)
  336. ]);
  337. }
  338. exit(json_encode(array(
  339. 'code' => 0
  340. )));
  341. }
  342. public function delCate()
  343. {
  344. $id = input('id/d');
  345. $cate = DemandCateModel::where('id',$id)->select();
  346. $result = $cate->delete();
  347. if ($result){
  348. exit(json_encode(array(
  349. 'code' => 0,
  350. 'msg' => ""
  351. )));
  352. }
  353. exit(json_encode(array(
  354. 'code' => 1,
  355. 'msg' => "删除失败,请稍后重试"
  356. )));
  357. }
  358. }