TalentCondition.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\common\AdminController;
  4. use app\common\api\TalentConditionApi;
  5. use think\facade\Db;
  6. /**
  7. * Description of TalentCondition
  8. *
  9. * @author sgq
  10. */
  11. class TalentCondition extends AdminController {
  12. /**
  13. * @auth {{/identifyCondition}}
  14. * @return type
  15. */
  16. function index() {
  17. return view();
  18. }
  19. /**
  20. * @auth {{/identifyCondition/list}}
  21. * @return type
  22. */
  23. function list() {
  24. $result = TalentConditionApi::getListByCondition($this->request->param());
  25. return json($result);
  26. }
  27. /**
  28. * @auth {{/identifyCondition/add}}
  29. * @return type
  30. */
  31. function add() {
  32. if ($this->request->isPost()) {
  33. $params = $this->request->param();
  34. $res = $this->myValid($params);
  35. if ($res !== true)
  36. return $res;
  37. if (TalentConditionApi::edit($params))
  38. return json(["code" => 200, "msg" => "添加认定条件成功"]);
  39. return json(["msg" => "添加认定条件失败"]);
  40. }
  41. return view("", ["type" => $this->user["type"]]);
  42. }
  43. /**
  44. * @auth {{/identifyCondition/update}}
  45. * @return type
  46. */
  47. function edit() {
  48. if ($this->request->isPost()) {
  49. $params = $this->request->param();
  50. $res = $this->myValid($params);
  51. if ($res !== true)
  52. return $res;
  53. if (TalentConditionApi::edit($params))
  54. return json(["code" => 200, "msg" => "编辑认定条件成功"]);
  55. return json(["msg" => "编辑认定条件失败"]);
  56. }
  57. $id = $this->request->param("id");
  58. $info = TalentConditionApi::getOne($id);
  59. return view("", ["info" => $info]);
  60. }
  61. private function myValid($params) {
  62. if (!$params["type"] || !in_array($params["type"], [1, 2, 5, 6]))
  63. return json(["msg" => "请选择人才类别"]);
  64. if (!$params["talentLevel"] || !in_array($params["talentLevel"], [1, 2, 3, 4, 5, 6, 7]))
  65. return json(["msg" => "请选择人才层次"]);
  66. if (!$params["talentLevelCat"] && in_array($params["type"], [1, 6]))
  67. return json(["msg" => "请选择人才条款"]);
  68. if (!$params["name"])
  69. return json(["msg" => "请填写名称"]);
  70. /* if (!$params["companyIds"]) {
  71. return json(["msg" => "没有设置审核单位"]);
  72. } */
  73. if ($params["companyIds"]) {
  74. if (!$params["bindFileTypes"]) {
  75. return json(["msg" => "没有设置审核附件"]);
  76. }
  77. $companyIds = array_filter(explode(",", $params["companyIds"]));
  78. $_total = count($companyIds);
  79. $_tmp = [];
  80. $bindFileTypes = array_filter(explode(",", $params["bindFileTypes"]));
  81. $total = count($bindFileTypes);
  82. $tmp = [];
  83. foreach ($params["relation"] as $_companyId => $_relation) {
  84. $_relations = explode(",", $_relation);
  85. for ($i = 0; $i < count($_relations); $i++) {
  86. if (in_array($_relations[$i], $bindFileTypes))
  87. $tmp[] = $_relations[$i];
  88. }
  89. if (in_array($_companyId, $companyIds))
  90. $_tmp[] = $_companyId;
  91. }
  92. $_valid_count = count(array_unique($_tmp));
  93. if ($_valid_count != $_total) {
  94. return json(["msg" => "存在审核单位没有成功关联附件"]);
  95. }
  96. $valid_count = count(array_unique($tmp));
  97. if ($valid_count != $total) {
  98. return json(["msg" => "选择了审核单位及审核附件后,每个附件必须与其中一个审核单位关联"]);
  99. }
  100. }
  101. return true;
  102. }
  103. /**
  104. * @auth {{/identifyCondition/delete}}
  105. * @return type
  106. */
  107. function delete() {
  108. $id = $this->request->param("id");
  109. TalentConditionApi::delete($id);
  110. return json(["code" => 200, "msg" => "删除成功"]);
  111. }
  112. /**
  113. * @auth {{/identifyCondition/import}}
  114. */
  115. function import() {
  116. ignore_user_abort(true);
  117. set_time_limit(0);
  118. if (!$this->request->file())
  119. return json(["msg" => "没有选择文件"]);
  120. $excel = $this->request->file("file");
  121. if (!isExcelFile($excel->getMime()))
  122. return json(["msg" => "不是正确的Excel文件"]);
  123. $mapping = [
  124. 0 => "type",
  125. 1 => "talentLevel",
  126. 2 => "name",
  127. 3 => "activeYear",
  128. 4 => "description"
  129. ];
  130. $path = $excel->getRealPath();
  131. $datas = getExcelDatas($path);
  132. $datas = array_slice($datas, 1); //去标题
  133. $inserts = [];
  134. while ($row = array_shift($datas)) {
  135. $cols = count($row);
  136. $companyIds = [];
  137. $new = [];
  138. for ($i = 0; $i < $cols; $i++) {
  139. if ($i < count($mapping)) {
  140. $new[$mapping[$i]] = $row[$i];
  141. } else {
  142. $companyIds[] = $row[$i];
  143. }
  144. }
  145. $new["companyIds"] = $companyIds ? implode(",", $companyIds) : null;
  146. $new["createTime"] = date("Y-m-d H:i:s");
  147. $inserts[] = $new;
  148. }
  149. $chunks = array_chunk($inserts, 200);
  150. foreach ($chunks as $chunk) {
  151. Db::table("new_talent_condition")->insertAll($chunk);
  152. }
  153. $data = ["code" => 200, "msg" => "导入成功"];
  154. echo sprintf('<script>parent.IdentifyCondition.callBack(%s);</script>', json_encode($data));
  155. }
  156. public function import1() {
  157. $datas = getExcelDatas("test.xls");
  158. $datas = array_slice($datas, 1); //去标题
  159. foreach ($datas as $k => $v) {
  160. $item = [];
  161. if ($v[4] != null) {
  162. switch ($v[1]) {
  163. case '第一层次':
  164. $item['talentLevel'] = 1;
  165. break;
  166. case '第二层次':
  167. $item['talentLevel'] = 2;
  168. break;
  169. case '第三层次':
  170. $item['talentLevel'] = 3;
  171. break;
  172. case '第四层次':
  173. $item['talentLevel'] = 4;
  174. break;
  175. case '第五层次':
  176. $item['talentLevel'] = 5;
  177. break;
  178. case '第六层次':
  179. $item['talentLevel'] = 6;
  180. break;
  181. case '第七层次':
  182. $item['talentLevel'] = 7;
  183. break;
  184. }
  185. $item['talentLevelCat'] = $v[2];
  186. $item['type'] = 1;
  187. $item['name'] = $v[3];
  188. $item['active'] = 1;
  189. $item['companyIds'] = $v[4];
  190. if ($v['5'] == null) {
  191. $item['bindFileTypes'] = 104;
  192. } else {
  193. $item['bindFileTypes'] = $v[5];
  194. }
  195. $item['companyWithFileType'] = $item['companyIds'] . ':' . $item['bindFileTypes'];
  196. if (strpos($item['name'], "年薪")) {
  197. $item['isSalary'] = 1;
  198. } else {
  199. $item['isSalary'] = 0;
  200. }
  201. Db::table("new_talent_condition")->insert($item);
  202. }
  203. }
  204. //dd($datas);
  205. }
  206. }