AisInfoCate.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 信息栏目
  7. */
  8. namespace app\ais\model;
  9. use think\Model;
  10. use category\Tree;
  11. class AisInfoCate extends Model{
  12. protected $pk = 'id';
  13. //开通好店订单
  14. public function tpl(){
  15. return $this->hasOne('AisInfoTpl','id','tpl_id');
  16. }
  17. //添加或编辑
  18. public static function edit($param){
  19. $data['title'] = $param['title'];
  20. $data['name'] = $param['name'];
  21. $data['sort'] = $param['sort'];
  22. $data['tpl_id'] = $param['tpl_id'];
  23. $data['update_time'] = time();
  24. if(empty($param['id'])){
  25. $data['create_time'] = time();
  26. $data['member_miniapp_id'] = $param['member_miniapp_id'];
  27. return self::insert($data);
  28. }else{
  29. return self::update($data,['id'=>(int)$param['id']]);
  30. }
  31. }
  32. /**
  33. * 获取当前栏目的模板
  34. * @param type $parent_id
  35. * @return type
  36. */
  37. public static function cateTpl(int $id){
  38. $rel = self::where(['id' => $id])->field('tpl_id')->find();
  39. $data = ['is_shop' => 0,'button_name' => '下单','users' => [],'fields' =>[]];
  40. if(isset($rel->tpl)){
  41. $fields = json_decode($rel->tpl->fields,true);
  42. foreach ($fields as $key => $value) {
  43. if($value['types'] == 'selector'){
  44. $fields[$key]['value'] = '';
  45. }else{
  46. $fields[$key]['value'] = $value['values'];
  47. }
  48. }
  49. $users = json_decode($rel->tpl->users,true);
  50. foreach ($users as $key => $value) {
  51. if($value['types'] == 'selector'){
  52. $users[$key]['value'] = '';
  53. }else{
  54. $users[$key]['value'] = $value['values'];
  55. }
  56. }
  57. $data['fields'] = $fields;
  58. $data['users'] = $users;
  59. $data['is_shop'] = $rel->tpl->is_shop;
  60. $data['button_name'] = $rel->tpl->button_name;
  61. }
  62. return $data;
  63. }
  64. }