AllwinInfoCate.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\allwin\model;
  9. use think\Model;
  10. use category\Tree;
  11. class AllwinInfoCate extends Model{
  12. protected $pk = 'id';
  13. //开通好店订单
  14. public function tpl(){
  15. return $this->hasOne('AllwinInfoTpl','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['picture'] = $param['picture'];
  23. $data['tpl_id'] = $param['tpl_id'];
  24. $data['update_time'] = time();
  25. if(isset($param['id'])){
  26. return self::update($data,['id'=>(int)$param['id']]);
  27. }else{
  28. $data['create_time'] = time();
  29. $data['member_miniapp_id'] = $param['member_miniapp_id'];
  30. return self::insert($data);
  31. }
  32. }
  33. /**
  34. * 获取当前栏目的模板
  35. * @param type $parent_id
  36. * @return type
  37. */
  38. public static function cateTpl(int $id){
  39. $rel = self::where(['id' => $id])->field('tpl_id')->find();
  40. $data = ['is_shop' => 0,'button_name' => '下单','users' => [],'fields' =>[]];
  41. if(isset($rel->tpl)){
  42. $fields = json_decode($rel->tpl->fields,true);
  43. foreach ($fields as $key => $value) {
  44. if($value['types'] == 'selector'){
  45. $fields[$key]['value'] = '';
  46. }else{
  47. $fields[$key]['value'] = $value['values'];
  48. }
  49. }
  50. $users = json_decode($rel->tpl->users,true);
  51. foreach ($users as $key => $value) {
  52. if($value['types'] == 'selector'){
  53. $users[$key]['value'] = '';
  54. }else{
  55. $users[$key]['value'] = $value['values'];
  56. }
  57. }
  58. $data['fields'] = $fields;
  59. $data['users'] = $users;
  60. $data['is_shop'] = $rel->tpl->is_shop;
  61. $data['button_name'] = $rel->tpl->button_name;
  62. }
  63. return $data;
  64. }
  65. }