TalentCondition.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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();
  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]))
  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"])
  67. return json(["msg" => "请选择人才条款"]);
  68. if (!$params["name"])
  69. return json(["msg" => "请填写名称"]);
  70. if (!$params["companyIds"]) {
  71. return json(["msg" => "没有设置审核单位"]);
  72. }
  73. if (!$params["bindFileTypes"]) {
  74. return json(["msg" => "没有设置审核附件"]);
  75. }
  76. $companyIds = array_filter(explode(",", $params["companyIds"]));
  77. $_total = count($companyIds);
  78. $_tmp = [];
  79. $bindFileTypes = array_filter(explode(",", $params["bindFileTypes"]));
  80. $total = count($bindFileTypes);
  81. $tmp = [];
  82. foreach ($params["relation"] as $_companyId => $_relation) {
  83. $_relations = explode(",", $_relation);
  84. for ($i = 0; $i < count($_relations); $i++) {
  85. if (in_array($_relations[$i], $bindFileTypes))
  86. $tmp[] = $_relations[$i];
  87. }
  88. if (in_array($_companyId, $companyIds))
  89. $_tmp[] = $_companyId;
  90. }
  91. $_valid_count = count(array_unique($_tmp));
  92. if ($_valid_count != $_total) {
  93. return json(["msg" => "存在审核单位没有成功关联附件"]);
  94. }
  95. $valid_count = count(array_unique($tmp));
  96. if ($valid_count != $total) {
  97. return json(["msg" => "选择了审核单位及审核附件后,每个附件必须与其中一个审核单位关联"]);
  98. }
  99. return true;
  100. }
  101. /**
  102. * @auth {{/identifyCondition/delete}}
  103. * @return type
  104. */
  105. function delete() {
  106. $id = $this->request->param("id");
  107. TalentConditionApi::delete($id);
  108. return json(["code" => 200, "msg" => "删除成功"]);
  109. }
  110. /**
  111. * @auth {{/identifyCondition/import}}
  112. */
  113. function import() {
  114. ignore_user_abort(true);
  115. set_time_limit(0);
  116. if (!$this->request->file())
  117. return json(["msg" => "没有选择文件"]);
  118. $excel = $this->request->file("file");
  119. if (!isExcelFile($excel->getMime()))
  120. return json(["msg" => "不是正确的Excel文件"]);
  121. $mapping = [
  122. 0 => "type",
  123. 1 => "talentLevel",
  124. 2 => "name",
  125. 3 => "activeYear",
  126. 4 => "description"
  127. ];
  128. $path = $excel->getRealPath();
  129. $datas = getExcelDatas($path);
  130. $datas = array_slice($datas, 1); //去标题
  131. $inserts = [];
  132. while ($row = array_shift($datas)) {
  133. $cols = count($row);
  134. $companyIds = [];
  135. $new = [];
  136. for ($i = 0; $i < $cols; $i++) {
  137. if ($i < count($mapping)) {
  138. $new[$mapping[$i]] = $row[$i];
  139. } else {
  140. $companyIds[] = $row[$i];
  141. }
  142. }
  143. $new["companyIds"] = $companyIds ? implode(",", $companyIds) : null;
  144. $new["createTime"] = date("Y-m-d H:i:s");
  145. $inserts[] = $new;
  146. }
  147. $chunks = array_chunk($inserts, 200);
  148. foreach ($chunks as $chunk) {
  149. Db::table("new_talent_condition")->insertAll($chunk);
  150. }
  151. $data = ["code" => 200, "msg" => "导入成功"];
  152. echo sprintf('<script>parent.IdentifyCondition.callBack(%s);</script>', json_encode($data));
  153. }
  154. public function import1(){
  155. $datas = getExcelDatas("test.xls");
  156. $datas = array_slice($datas, 1); //去标题
  157. foreach ($datas as $k => $v){
  158. $item = [];
  159. if($v[4] != null){
  160. switch ($v[1]){
  161. case '第一层次':
  162. $item['talentLevel'] = 1;
  163. break;
  164. case '第二层次':
  165. $item['talentLevel'] = 2;
  166. break;
  167. case '第三层次':
  168. $item['talentLevel'] = 3;
  169. break;
  170. case '第四层次':
  171. $item['talentLevel'] = 4;
  172. break;
  173. case '第五层次':
  174. $item['talentLevel'] = 5;
  175. break;
  176. case '第六层次':
  177. $item['talentLevel'] = 6;
  178. break;
  179. case '第七层次':
  180. $item['talentLevel'] = 7;
  181. break;
  182. }
  183. $item['talentLevelCat'] = $v[2];
  184. $item['type'] = 1;
  185. $item['name'] = $v[3];
  186. $item['active'] = 1;
  187. $item['companyIds'] = $v[4];
  188. if($v['5'] == null){
  189. $item['bindFileTypes'] = 104;
  190. }else{
  191. $item['bindFileTypes'] = $v[5];
  192. }
  193. $item['companyWithFileType'] = $item['companyIds'] . ':' . $item['bindFileTypes'];
  194. if(strpos($item['name'],"年薪")){
  195. $item['isSalary'] = 1;
  196. }else{
  197. $item['isSalary'] = 0;
  198. }
  199. Db::table("new_talent_condition")->insert($item);
  200. }
  201. }
  202. //dd($datas);
  203. }
  204. }