CitysCate.php 2.3 KB

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