WebsiteService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Ad;
  4. use App\Model\AdPlace;
  5. use App\Model\Article;
  6. use App\Model\Department;
  7. use App\Model\District;
  8. use App\Model\Link;
  9. use App\Model\TemplateClass;
  10. use App\Model\Template;
  11. use App\Model\WebsiteRole;
  12. use App\Model\WebsiteRoleUser;
  13. use App\Model\Website;
  14. use App\Model\WebsiteColumn;
  15. use Hyperf\RpcServer\Annotation\RpcService;
  16. use App\Tools\Result;
  17. use App\Model\WebsiteCategory;
  18. use Carbon\Carbon;
  19. use Directory;
  20. use MathPHP\Exception\FunctionFailedToConvergeException;
  21. use function PHPUnit\Framework\isNull;
  22. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  23. class WebsiteService implements WebsiteServiceInterface
  24. {
  25. /**
  26. * @param string $keyword
  27. * @param int $page
  28. * @param int $pageSize
  29. * @return array
  30. */
  31. public function getWebsitetList(array $data): array
  32. {
  33. $where = [];
  34. if(isset($data['keyword']) && !empty($data['keyword'])){
  35. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  36. }
  37. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  38. array_push($where,['website.website_column_id','=',$data['website_column_id']]);
  39. }
  40. if(isset($data['city_id']) && !empty($data['city_id'])){
  41. array_push($where,['website.city_id','=',$data['city_id']]);
  42. }
  43. $result = Website::where($where)
  44. ->leftJoin("website_column","website.website_column_id","website_column.id")
  45. ->leftJoin("district","district.id","website.city_id")
  46. ->select("website.*","website_column.column_name","district.name as city_name")
  47. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->get();
  48. $count = Website::where($where)->count();
  49. if (empty($result)) {
  50. return Result::error("没有数据",0);
  51. }
  52. $data = [
  53. 'rows'=>$result->toArray(),
  54. 'count'=>$count
  55. ];
  56. return Result::success($data);
  57. }
  58. /**
  59. * @param array $data
  60. * @return array
  61. */
  62. public function createWebsite(array $data): array
  63. {
  64. var_dump("网站数据:",$data);
  65. $insertData = [
  66. 'website_name'=>$data['website_name'],
  67. 'logo'=>$data['logo']??'',
  68. 'website_url'=>$data['website_url']??'',
  69. 'city_id'=>$data['city_id']??0,
  70. 'website_column_id'=>$data['website_column_id'],
  71. 'title'=>$data['title']??'',
  72. 'keywords'=>$data['keywords']??'',
  73. 'description'=>$data['description']??'',
  74. 'status'=>$data['status']??0,
  75. 'website_column_arr_id'=>$data['website_column_arr_id'],
  76. 'city_arr_id'=>$data['city_arr_id']??[0],
  77. 'template_id' =>$data['template_id']??0,
  78. ];
  79. $result = Website::insertGetId($insertData);
  80. if(empty($result)){
  81. return Result::error("创建失败",0);
  82. }else{
  83. return Result::success(["id"=>$result]);
  84. }
  85. }
  86. /**
  87. * @param int $id
  88. * @param array $data
  89. * @return array
  90. */
  91. public function updateWebsite(int $id,array $data): array
  92. {
  93. $insertData = [
  94. 'website_name'=>$data['website_name'],
  95. 'logo'=>$data['logo']??'',
  96. 'website_url'=>$data['website_url']??'',
  97. 'city_id'=>$data['city_id']??0,
  98. 'website_column_id'=>$data['website_column_id'],
  99. 'title'=>$data['title']??'',
  100. 'keywords'=>$data['keywords']??'',
  101. 'description'=>$data['description']??'',
  102. 'status'=>$data['status']??0,
  103. 'website_column_arr_id'=>$data['website_column_arr_id'],
  104. 'city_arr_id'=>$data['city_arr_id']??[0],
  105. 'template_id' =>$data['template_id']??0,
  106. ];
  107. $result = Website::where('id',$id)->update($insertData);
  108. var_dump("更新站点",$result);
  109. if(empty($result)){
  110. return Result::error("更新失败",0);
  111. }else{
  112. return Result::success();
  113. }
  114. }
  115. /**
  116. * @param int $id
  117. * @return array
  118. */
  119. public function delWebsite(int $id): array
  120. {
  121. $result = Website::where('id',$id )->delete();
  122. var_dump("删除站点",$result);
  123. if(empty($result)){
  124. return Result::error("删除失败",0);
  125. }else{
  126. return Result::success();
  127. }
  128. }
  129. /**
  130. * @param int $id
  131. * @return array
  132. */
  133. public function getWebsiteInfo(int $id): array
  134. {
  135. $where = [
  136. ['website.id','=',$id]
  137. ];
  138. $result = Website::where($where )
  139. ->leftJoin("template","template.id","website.template_id")
  140. ->select("website.*","template.template_name","template.template_img")
  141. ->first();
  142. if(empty($result)){
  143. return Result::error("数据不存在",0);
  144. }else{
  145. return Result::success($result->toArray());
  146. }
  147. }
  148. /**
  149. * 查询所有的站点栏目
  150. * @return array
  151. */
  152. public function getWebsiteColumn(array $data): array
  153. {
  154. $result = WebsiteColumn::where($data)->get();
  155. if(empty($result)){
  156. return Result::error("数据不存在",0);
  157. }else{
  158. return Result::success($result->toArray());
  159. }
  160. }
  161. /**
  162. * @param string $keyword
  163. * @param int $page
  164. * @param int $pageSize
  165. * @return array
  166. */
  167. public function getWebsiteColumnList(string $keyword,int $page,int $pageSize):array
  168. {
  169. $where = [
  170. ['website_column.column_name','like','%'.$keyword.'%']
  171. ];
  172. $result = WebsiteColumn::where($where)
  173. ->leftJoin("website_column as wc","website_column.pid","wc.id")
  174. ->select("website_column.*","wc.column_name as parent_column_name")
  175. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  176. $count = WebsiteColumn::where($where)->count();
  177. if (empty($result)) {
  178. return Result::error("没有数据",0);
  179. }
  180. $data = [
  181. 'rows'=>$result->toArray(),
  182. 'count'=>$count
  183. ];
  184. return Result::success($data);
  185. }
  186. /**
  187. * @param array $data
  188. * @return array
  189. */
  190. public function createWebsiteColumn(array $data): array
  191. {
  192. $insertData = [
  193. 'column_name'=>$data['column_name'],
  194. 'pid'=>$data['pid']??'',
  195. 'column_arr_id'=>$data['column_arr_id']??[0],
  196. 'sort'=>$data['sort']??0,
  197. 'remark'=>$data['remark']??'',
  198. ];
  199. $result = WebsiteColumn::insertGetId($insertData);
  200. if(empty($result)){
  201. return Result::error("创建失败",0);
  202. }else{
  203. return Result::success(["id"=>$result]);
  204. }
  205. }
  206. /**
  207. * @param int $id
  208. * @param array $data
  209. * @return array
  210. */
  211. public function updateWebsiteColumn(int $id,array $data): array
  212. {
  213. $insertData = [
  214. 'column_name'=>$data['column_name'],
  215. 'pid'=>$data['pid']??'',
  216. 'column_arr_id'=>$data['column_arr_id']??[0],
  217. 'sort'=>$data['sort']??0,
  218. 'remark'=>$data['remark']??'',
  219. ];
  220. $result = WebsiteColumn::where('id',$id)->update($insertData);
  221. if(empty($result)){
  222. return Result::error("更新失败",0);
  223. }else{
  224. return Result::success();
  225. }
  226. }
  227. /**
  228. * @param int $id
  229. * @return array
  230. */
  231. public function delWebsiteColumn(int $id): array
  232. {
  233. $result = WebsiteColumn::where('id',$id )->delete();
  234. if(empty($result)){
  235. return Result::error("删除失败",0);
  236. }else{
  237. return Result::success();
  238. }
  239. }
  240. /**
  241. * @param string $keyword
  242. * @param int $page
  243. * @param int $pageSize
  244. * @return array
  245. */
  246. public function getWebsiteRoleList(string $keyword,int $page,int $pageSize,int $websiteId):array
  247. {
  248. $where = [
  249. ['role.role_name','like','%'.$keyword.'%'],
  250. ['website_role.website_id','=',$websiteId],
  251. ];
  252. $result = WebsiteRole::where($where)
  253. ->leftJoin("role","role.id","website_role.role_id")
  254. ->select("role.*","website_role.type","website_role.role_id","website_role.id as website_role_id","website_role.website_id")
  255. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  256. $count = WebsiteRole::where($where) ->leftJoin("role","role.id","website_role.role_id")->count();
  257. if (empty($result)) {
  258. return Result::error("没有数据",0);
  259. }
  260. $data = [
  261. 'rows'=>$result->toArray(),
  262. 'count'=>$count
  263. ];
  264. return Result::success($data);
  265. }
  266. /**
  267. * @param array $data
  268. * @return array
  269. */
  270. public function createWebsiteRole(array $data): array
  271. {
  272. $insertData = [
  273. 'website_id'=>$data['website_id'],
  274. 'role_id'=>$data['role_id']??''
  275. ];
  276. $info = WebsiteRole::where($insertData)->first();
  277. if($info){
  278. return Result::error("不能重复添加角色",0);
  279. }
  280. $insertData['admin_user_id'] = $data['admin_user_id']??'';
  281. $insertData['type'] = $data['type']??'';
  282. $result = WebsiteRole::insertGetId($insertData);
  283. if(empty($result)){
  284. return Result::error("创建失败",0);
  285. }else{
  286. return Result::success(["id"=>$result]);
  287. }
  288. }
  289. /**
  290. * 暂时用不上
  291. * @param int $id
  292. * @param array $data
  293. * @return array
  294. */
  295. public function updateWebsiteRole(int $id,array $data): array
  296. {
  297. $insertData = [
  298. 'website_id'=>$data['website_id'],
  299. 'type'=>$data['type']??'',
  300. ];
  301. $result = WebsiteRole::where('id',$id)->update($insertData);
  302. if(empty($result)){
  303. return Result::error("更新失败",0);
  304. }else{
  305. return Result::success();
  306. }
  307. }
  308. /**
  309. * @param int $id
  310. * @return array
  311. */
  312. public function delWebsiteRole(int $id): array
  313. {
  314. $result = WebsiteRole::where('id',$id )->delete();
  315. if(empty($result)){
  316. return Result::error("删除失败",0);
  317. }else{
  318. return Result::success();
  319. }
  320. }
  321. /**
  322. * @param string $keyword
  323. * @param int $page
  324. * @param int $pageSize
  325. * @return array
  326. */
  327. public function getWebsiteRoleUserList(string $keyword,int $page,int $pageSize,int $websiteId,int $roleId):array
  328. {
  329. $where = [
  330. ['website_role_user.website_id','=',$websiteId],
  331. ['website_role_user.role_id','=',$roleId],
  332. ];
  333. $count = WebsiteRoleUser::where($where)->count();
  334. $where[] = ['u.user_name','like','%'.$keyword.'%'];
  335. $result = WebsiteRoleUser::where($where)
  336. ->leftJoin("user as u","website_role_user.user_id","u.id")
  337. ->leftJoin("website as w","website_role_user.website_id","u.id")
  338. ->leftJoin("role as r","website_role_user.role_id","r.id")
  339. ->select("u.*","u.user_name",'w.website_name','r.role_name','website_role_user.id as website_role_user_id','website_role_user.updated_at as user_update_at')
  340. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  341. if (empty($result)) {
  342. return Result::error("没有数据",0);
  343. }
  344. $data = [
  345. 'rows'=>$result->toArray(),
  346. 'count'=>$count
  347. ];
  348. return Result::success($data);
  349. }
  350. /**
  351. * @param array $data
  352. * @return array
  353. */
  354. public function createWebsiteRoleUser(array $data): array
  355. {
  356. $insertData = [
  357. 'website_id'=>$data['website_id'],
  358. 'user_id'=>$data['user_id']??'',
  359. ];
  360. $info = WebsiteRoleUser::where($insertData)->first();
  361. if($info){
  362. return Result::error("不能重复添加角色用户",0);
  363. }
  364. $insertData['role_id'] = $data['role_id']??'';
  365. $insertData['admin_user_id'] = $data['admin_user_id']??'';
  366. $insertData['type'] = $data['type']??'';
  367. $result = WebsiteRoleUser::insertGetId($insertData);
  368. if(empty($result)){
  369. return Result::error("创建失败",0);
  370. }else{
  371. return Result::success(["id"=>$result]);
  372. }
  373. }
  374. /**
  375. * @param int $id
  376. * @param array $data
  377. * @return array
  378. */
  379. public function updateWebsiteRoleUser(int $id,array $data): array
  380. {
  381. $insertData = [
  382. 'website_id'=>$data['website_id'],
  383. 'type'=>$data['type']??'',
  384. 'type_id'=>$data['type_id']??'',
  385. 'role_id'=>$data['role_id']??'',
  386. ];
  387. $result = WebsiteRoleUser::where('id',$id)->update($insertData);
  388. if(empty($result)){
  389. return Result::error("更新失败",0);
  390. }else{
  391. return Result::success();
  392. }
  393. }
  394. /**
  395. * @param int $id
  396. * @return array
  397. */
  398. public function delWebsiteRoleUser(int $id): array
  399. {
  400. $result = WebsiteRoleUser::where('id',$id )->delete();
  401. if(empty($result)){
  402. return Result::error("删除失败",0);
  403. }else{
  404. return Result::success();
  405. }
  406. }
  407. /**
  408. * 根据域名获取网站 站点id
  409. * @param array $data
  410. * @return array
  411. */
  412. public function getWebsiteId(array $data): array
  413. {
  414. $where = [
  415. 'website_url'=>$data['website_url']
  416. ];
  417. $result = Website::where($where)->first();
  418. if(empty($result)){
  419. return Result::error("查询站点失败",0);
  420. }else{
  421. return Result::success($result);
  422. }
  423. }
  424. /**
  425. * 查询网站下面的导航
  426. * @param array $data
  427. * @return array
  428. */
  429. public function getWebsiteCategory(array $data): array
  430. {
  431. $where = [
  432. 'website_id'=>$data['website_id'],
  433. 'pid'=>0
  434. ];
  435. $result = WebsiteCategory::where($where)->limit($data['pageSize'])->orderBy('sort','asc')->get();
  436. if(empty($result)){
  437. return Result::error("查询站点栏目失败",0);
  438. }else{
  439. return Result::success($result);
  440. }
  441. }
  442. /**
  443. * 查询网站的广告
  444. * @param array $data
  445. * @return array
  446. */
  447. public function getWebsiteAdvertisement(array $data): array
  448. {
  449. $where = [
  450. 'website_id' => $data['website_id'],
  451. 'id' => $data['ad_placeid']
  452. ];
  453. $ad_place = AdPlace::where($where)->orderBy('id','asc')->limit(1)->get();
  454. $today = Carbon::now();
  455. if(empty($ad_place)){
  456. return Result::error("error",0);
  457. }else{
  458. foreach($ad_place as $val){
  459. $adplaceid = $val;
  460. }
  461. $ad=Ad::where('pid',$adplaceid['id'])->where('status',1)->orderBy('id','asc')->get();
  462. if(empty($ad)){
  463. $result=$adplaceid;
  464. return Result::success($result);
  465. }else{
  466. foreach($ad as $i)
  467. {
  468. $starttime=Carbon::parse($i['fromtime']);
  469. $endtime=Carbon::parse($i['totime']);
  470. $time=$today->between($starttime,$endtime);
  471. if($time)
  472. {
  473. $result=$i;
  474. }
  475. }
  476. if(empty($result)){
  477. $result=$ad;
  478. return Result::success($result);
  479. }else{
  480. return Result::success($result);
  481. }
  482. }
  483. }
  484. }
  485. /**
  486. *
  487. * @param array $data
  488. * @return array
  489. */
  490. /**网站行政职能搜索 */
  491. public function selectWebsiteDepartment(array $data): array
  492. {
  493. $depart = Department::where('pid',0)->orderBy('id','asc')->limit(10)->get();
  494. if(isset($data['keyword']) && !empty($data['keyword'])){
  495. $departments= Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  496. if(empty($departments)){
  497. $result['message']="未查询到与此相关职能部门";
  498. }else{
  499. $count = Department::where('name','like',"%{$data['keyword']}%")->count();
  500. $m = [
  501. 'department'=>$depart,
  502. 'type'=>$departments,
  503. 'count'=>$count
  504. ];
  505. }
  506. $result['sele'] = $m;
  507. return Result::success($result['sele']);
  508. }
  509. $result=$depart;
  510. return Result::success($result['data']);
  511. }
  512. /**
  513. * 搜索地区
  514. */
  515. public function selectWebsiteArea(array $data): array
  516. {
  517. $provinces=District::where('pid',0)->where('status',1)->get();
  518. if(isset($data['province'])){
  519. $province=District::where('pid',0)->where('status',1)->where('id',$data['province'])->orderBy('id')->get();
  520. $province=$province->toArray();
  521. if(!empty($province)){
  522. $citys=District::where('pid',$data['province'])->where('status',1)->orderBy('id')->get();
  523. if(!empty($citys) && isset($data['city']) && !empty($data['city'])){
  524. // $province = $province->toArray();
  525. $province_id=[];
  526. foreach($province as $val){
  527. array_push($province_id,$val['id']);
  528. }
  529. // var_dump($province_id);
  530. $city=District::whereIn('pid',$province_id)->where('status',1)->where('id',$data['city'])->orderBy('id')->get();
  531. if(!empty($city)){
  532. $city_id=[];
  533. foreach($city as $val){
  534. array_push($city_id,$val['id']);
  535. }
  536. $regions=District::whereIn('pid',$city_id)->where('status',1)->orderBy('id')->get();
  537. $result=[
  538. 'province' => $province,
  539. 'city' => $city,
  540. 'region' => $regions
  541. ];
  542. }else{
  543. return Result::error("未查询到此城市",0);
  544. }
  545. }else{
  546. $result=[
  547. 'province' => $province,
  548. 'city' => $citys,
  549. 'region' => null
  550. ];
  551. }
  552. }else{
  553. return Result::error("未查询到此省份",0);
  554. }
  555. }else{
  556. // $keys = array('data');
  557. $result = $provinces;
  558. }
  559. return Result::success($result);
  560. }
  561. /**
  562. * @param array $data
  563. * @return array
  564. */
  565. //获取栏目
  566. public function getWebsiteModelCategory(array $data): array
  567. {
  568. $website_id=[
  569. 'website_id' => $data['website_id']
  570. ];
  571. $placeid=$data['placeid']-1;
  572. $pid=[
  573. 'pid' => $data['pid'],
  574. ];
  575. $num = $data['num'];
  576. $result=WebsiteCategory::where($website_id)->where($pid)->orderBy('sort')->offset($placeid)->limit($num)->get();
  577. $result = $result->toArray();
  578. if(!empty($result)){
  579. return Result::success($result);
  580. }else{
  581. return Result::error("本网站暂无栏目",0);
  582. }
  583. }
  584. /**
  585. * @param array $data
  586. * @return array
  587. */
  588. //获取友情链接
  589. public function selectWebsiteLinks(array $data): array
  590. {
  591. $where = [
  592. 'website_id' => $data['website_id'],
  593. 'status' => 1,
  594. 'type' => $data['type']
  595. ];
  596. $num=$data['num'];
  597. $result=Link::where($where)->orderBy('id')->limit($num)->get();
  598. if(!empty($result)){
  599. return Result::success($result);
  600. }else{
  601. return Result::error("本网站暂无此类型友情链接",0);
  602. }
  603. }
  604. /**
  605. * 网站首页数据统计, 管理员
  606. * @return void
  607. */
  608. public function getAdminIndex(array $data): array
  609. {
  610. return [];
  611. }
  612. /**
  613. * 获取模板类型
  614. * @return void
  615. */
  616. public function getTemplateClass(array $data): array
  617. {
  618. $result = TemplateClass::orderBy('sort','asc')->get();
  619. if(empty($result)){
  620. return Result::error("没有模板类型",0);
  621. }else{
  622. return Result::success($result);
  623. }
  624. }
  625. /**
  626. * 添加模板类型
  627. * @param
  628. * @return void
  629. */
  630. public function addTemplateClass(array $data): array
  631. {
  632. $insertData = [
  633. 'name'=>$data['name']
  634. ];
  635. $result = TemplateClass::insertGetId($insertData);
  636. if(empty($result)){
  637. return Result::error("创建失败",0);
  638. }else{
  639. return Result::success(["id"=>$result]);
  640. }
  641. }
  642. /**
  643. * 更新模板
  644. * @param array $data
  645. * @return array
  646. */
  647. public function upTemplateClass(array $data): array
  648. {
  649. $where = [
  650. 'id'=>$data['id']
  651. ];
  652. $insertData = [
  653. 'name'=>$data['name']
  654. ];
  655. $result = TemplateClass::where($where)->update($insertData);
  656. if(empty($result)){
  657. return Result::error("更新失败",0);
  658. }else{
  659. return Result::success();
  660. }
  661. }
  662. /**
  663. * 删除模板
  664. * @param array $data
  665. * @return array
  666. */
  667. public function delTemplateClass(array $data): array
  668. {
  669. $where = [
  670. 'id'=>$data['id']
  671. ];
  672. $result = TemplateClass::where($where)->delete();
  673. if(empty($result)){
  674. return Result::error("删除失败",0);
  675. }else{
  676. return Result::success();
  677. }
  678. }
  679. /**
  680. * 获取分类下的模板
  681. * @param array $data
  682. * @return array
  683. */
  684. public function getTemplate(array $data): array
  685. {
  686. $page = $data['page'];
  687. $pageSize = $data['pageSize'];
  688. $where = [
  689. 'template_class_id'=> $data['template_class_id']
  690. ];
  691. $result = Template::where($where)
  692. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  693. $count = Template::where($where)->count();
  694. if (empty($result)) {
  695. return Result::error("没有数据",0);
  696. }
  697. $data = [
  698. 'rows'=>$result->toArray(),
  699. 'count'=>$count
  700. ];
  701. return Result::success($data);
  702. }
  703. /**
  704. * 创建模板
  705. * @param
  706. * @return void
  707. */
  708. public function addTemplate(array $data): array
  709. {
  710. $insertData = [
  711. 'template_name'=>$data['template_name'],
  712. 'template_img'=>json_encode($data['template_img']),
  713. 'template_class_id'=>$data['template_class_id'],
  714. ];
  715. $result = Template::insertGetId($insertData);
  716. if(empty($result)){
  717. return Result::error("创建模板失败",0);
  718. }else{
  719. return Result::success(["id"=>$result]);
  720. }
  721. }
  722. /**
  723. * 更新模板
  724. * @param array $data
  725. * @return array
  726. */
  727. public function upTemplate(array $data): array
  728. {
  729. $where = [
  730. 'id'=>$data['id']
  731. ];
  732. $insertData = [
  733. 'template_name'=>$data['template_name'],
  734. 'template_img'=>json_encode($data['template_img']),
  735. 'template_class_id'=>$data['template_class_id'],
  736. ];
  737. $result = Template::where($where)->update($insertData);
  738. if(empty($result)){
  739. return Result::error("更新模板失败",0);
  740. }else{
  741. return Result::success();
  742. }
  743. }
  744. /**
  745. * 删除模板
  746. * @param array $data
  747. * @return array
  748. */
  749. public function delTemplate(array $data): array
  750. {
  751. $where = [
  752. 'id'=>$data['id']
  753. ];
  754. $result = Template::where($where)->delete();
  755. if(empty($result)){
  756. return Result::error("删除模板失败",0);
  757. }else{
  758. return Result::success();
  759. }
  760. }
  761. }