WebsiteService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  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. * @param array $data
  515. * @return array
  516. */
  517. /**
  518. * 搜索地区
  519. */
  520. public function selectWebsiteArea(array $data): array
  521. {
  522. $provinces=District::where('pid',0)->where('status',1)->get();
  523. if(isset($data['province'])){
  524. $province=District::where('pid',0)->where('status',1)->where('id',$data['province'])->orderBy('id')->get();
  525. $province=$province->toArray();
  526. if(!empty($province)){
  527. $citys=District::where('pid',$data['province'])->where('status',1)->orderBy('id')->get();
  528. if(!empty($citys) && isset($data['city']) && !empty($data['city'])){
  529. // $province = $province->toArray();
  530. $province_id=[];
  531. foreach($province as $val){
  532. array_push($province_id,$val['id']);
  533. }
  534. // var_dump($province_id);
  535. $city=District::whereIn('pid',$province_id)->where('status',1)->where('id',$data['city'])->orderBy('id')->get();
  536. if(!empty($city)){
  537. $city_id=[];
  538. foreach($city as $val){
  539. array_push($city_id,$val['id']);
  540. }
  541. $regions=District::whereIn('pid',$city_id)->where('status',1)->orderBy('id')->get();
  542. $result=[
  543. 'province' => $province,
  544. 'city' => $city,
  545. 'region' => $regions
  546. ];
  547. }else{
  548. return Result::error("未查询到此城市",0);
  549. }
  550. }else{
  551. $result=[
  552. 'province' => $province,
  553. 'city' => $citys,
  554. 'region' => null
  555. ];
  556. }
  557. }else{
  558. return Result::error("未查询到此省份",0);
  559. }
  560. }else{
  561. // $keys = array('data');
  562. $result = $provinces;
  563. }
  564. return Result::success($result);
  565. }
  566. /**
  567. * @param array $data
  568. * @return array
  569. */
  570. //获取栏目
  571. public function getWebsiteModelCategory(array $data): array
  572. {
  573. $website_id=[
  574. 'website_id' => $data['website_id']
  575. ];
  576. $placeid=$data['placeid']-1;
  577. $pid=[
  578. 'pid' => $data['pid'],
  579. ];
  580. $num = $data['num'];
  581. $result=WebsiteCategory::where($website_id)->where($pid)->orderBy('sort')->offset($placeid)->limit($num)->get();
  582. $result = $result->toArray();
  583. if(!empty($result)){
  584. return Result::success($result);
  585. }else{
  586. return Result::error("本网站暂无栏目",0);
  587. }
  588. }
  589. /**
  590. * @param array $data
  591. * @return array
  592. */
  593. //获取友情链接
  594. public function selectWebsiteLinks(array $data): array
  595. {
  596. $where = [
  597. 'website_id' => $data['website_id'],
  598. 'status' => 1,
  599. 'type' => $data['type']
  600. ];
  601. $num=$data['num'];
  602. $result=Link::where($where)->orderBy('id')->limit($num)->get();
  603. if(!empty($result)){
  604. return Result::success($result);
  605. }else{
  606. return Result::error("本网站暂无此类型友情链接",0);
  607. }
  608. }
  609. /**
  610. * 网站首页数据统计, 管理员
  611. * @return void
  612. */
  613. public function getAdminIndex(array $data): array
  614. {
  615. return [];
  616. }
  617. /**
  618. * 获取模板类型
  619. * @return void
  620. */
  621. public function getTemplateClass(array $data): array
  622. {
  623. $result = TemplateClass::orderBy('sort','asc')->get();
  624. if(empty($result)){
  625. return Result::error("没有模板类型",0);
  626. }else{
  627. return Result::success($result);
  628. }
  629. }
  630. /**
  631. * 添加模板类型
  632. * @param
  633. * @return void
  634. */
  635. public function addTemplateClass(array $data): array
  636. {
  637. $insertData = [
  638. 'name'=>$data['name']
  639. ];
  640. $result = TemplateClass::insertGetId($insertData);
  641. if(empty($result)){
  642. return Result::error("创建失败",0);
  643. }else{
  644. return Result::success(["id"=>$result]);
  645. }
  646. }
  647. /**
  648. * 更新模板
  649. * @param array $data
  650. * @return array
  651. */
  652. public function upTemplateClass(array $data): array
  653. {
  654. $where = [
  655. 'id'=>$data['id']
  656. ];
  657. $insertData = [
  658. 'name'=>$data['name']
  659. ];
  660. $result = TemplateClass::where($where)->update($insertData);
  661. if(empty($result)){
  662. return Result::error("更新失败",0);
  663. }else{
  664. return Result::success();
  665. }
  666. }
  667. /**
  668. * 删除模板
  669. * @param array $data
  670. * @return array
  671. */
  672. public function delTemplateClass(array $data): array
  673. {
  674. $where = [
  675. 'id'=>$data['id']
  676. ];
  677. $result = TemplateClass::where($where)->delete();
  678. if(empty($result)){
  679. return Result::error("删除失败",0);
  680. }else{
  681. return Result::success();
  682. }
  683. }
  684. /**
  685. * 获取分类下的模板
  686. * @param array $data
  687. * @return array
  688. */
  689. public function getTemplate(array $data): array
  690. {
  691. $page = $data['page'];
  692. $pageSize = $data['pageSize'];
  693. $where = [
  694. 'template_class_id'=> $data['template_class_id']
  695. ];
  696. $result = Template::where($where)
  697. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  698. $count = Template::where($where)->count();
  699. if (empty($result)) {
  700. return Result::error("没有数据",0);
  701. }
  702. $data = [
  703. 'rows'=>$result->toArray(),
  704. 'count'=>$count
  705. ];
  706. return Result::success($data);
  707. }
  708. /**
  709. * 创建模板
  710. * @param
  711. * @return void
  712. */
  713. public function addTemplate(array $data): array
  714. {
  715. $insertData = [
  716. 'template_name'=>$data['template_name'],
  717. 'template_img'=>json_encode($data['template_img']),
  718. 'template_class_id'=>$data['template_class_id'],
  719. ];
  720. $result = Template::insertGetId($insertData);
  721. if(empty($result)){
  722. return Result::error("创建模板失败",0);
  723. }else{
  724. return Result::success(["id"=>$result]);
  725. }
  726. }
  727. /**
  728. * 更新模板
  729. * @param array $data
  730. * @return array
  731. */
  732. public function upTemplate(array $data): array
  733. {
  734. $where = [
  735. 'id'=>$data['id']
  736. ];
  737. $insertData = [
  738. 'template_name'=>$data['template_name'],
  739. 'template_img'=>json_encode($data['template_img']),
  740. 'template_class_id'=>$data['template_class_id'],
  741. ];
  742. $result = Template::where($where)->update($insertData);
  743. if(empty($result)){
  744. return Result::error("更新模板失败",0);
  745. }else{
  746. return Result::success();
  747. }
  748. }
  749. /**
  750. * 删除模板
  751. * @param array $data
  752. * @return array
  753. */
  754. public function delTemplate(array $data): array
  755. {
  756. $where = [
  757. 'id'=>$data['id']
  758. ];
  759. $result = Template::where($where)->delete();
  760. if(empty($result)){
  761. return Result::error("删除模板失败",0);
  762. }else{
  763. return Result::success();
  764. }
  765. }
  766. }