StoreProductProvider.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace app\admin\controller\store;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\store\StoreProductProvider as SPP;
  5. use crmeb\services\FormBuilder as Form;
  6. use crmeb\services\JsonService;
  7. use crmeb\services\UtilService;
  8. use think\facade\Route as Url;
  9. class StoreProductProvider extends AuthController
  10. {
  11. public function index()
  12. {
  13. return $this->fetch();
  14. }
  15. public function get_providers()
  16. {
  17. $where = UtilService::getMore([
  18. ['page', 0],
  19. ['limit', 10],
  20. ['keyword', ''],
  21. ]);
  22. return JsonService::successlayui(SPP::getProviderList($where));
  23. }
  24. public function create($id=0)
  25. {
  26. if ($id) {
  27. $pvdr = SPP::get($id);
  28. }
  29. $field[] = Form::text('name', '名称', isset($pvdr) ? $pvdr->name : '')->col(12);
  30. $field[] = Form::text('site', '网站', isset($pvdr) ? $pvdr->site : '');
  31. $field[] = Form::frameImageOne('logo', 'logo(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'logo')), isset($pvdr) ? $pvdr->logo : '')->icon('image')->width('100%')->height('500px');
  32. $field[] = Form::text('source', '来源', isset($pvdr) ? $pvdr->source : '')->col(12);
  33. $field[] = Form::text('contact', '联系人', isset($pvdr) ? $pvdr->contact : '')->col(12);
  34. $field[] = Form::text('phone', '电话', isset($pvdr) ? $pvdr->phone : '')->col(12);
  35. $field[] = Form::text('qq', 'qq', isset($pvdr) ? $pvdr->qq : '')->col(12);
  36. $field[] = Form::text('wechat', '微信', isset($pvdr) ? $pvdr->wechat : '')->col(12);
  37. $field[] = Form::textarea('desc', '描述', isset($pvdr) ? $pvdr->desc : '')->rows(3);
  38. $field[] = Form::select('status', '状态', isset($pvdr) ? strval($pvdr->status) : '0')->setOptions([
  39. ['label'=>'默认', 'value'=>'0'],
  40. ['label'=>'下架', 'value'=>'1'],
  41. ['label'=>'删除', 'value'=>'2'],
  42. ]) ->col(12);
  43. $form = Form::make_post_form('供应商', $field, Url::buildUrl('save', ['id' => $id]), 2);
  44. $this->assign(compact('form'));
  45. return $this->fetch('public/form-builder');
  46. }
  47. public function save($id=0)
  48. {
  49. $data = UtilService::postMore([
  50. ['name', ''],
  51. ['site', ''],
  52. ['logo', 0],
  53. ['source', ''],
  54. ['contact', ''],
  55. ['phone', ''],
  56. ['qq', 0],
  57. ['wechat', 0],
  58. ['desc', 0],
  59. ['status', 0],
  60. ]);
  61. if (!$data['name']) {
  62. return JsonService::fail('请输入名称');
  63. }
  64. if ($data['status'] < 0 || $data['status'] > 2) {
  65. return JsonService::fail('参数错误');
  66. }
  67. try {
  68. if ($id) {
  69. $res = SPP::edit($data, $id);
  70. } else {
  71. $data['add_time'] = time();
  72. $res = SPP::create($data);
  73. }
  74. if ($res) {
  75. return JsonService::successful('保存成功');
  76. }else{
  77. return JsonService::fail('保存失败');
  78. }
  79. } catch (\Exception $e) {
  80. return JsonService::fail($e->getMessage());
  81. }
  82. }
  83. public function mark($id=0,$st=0)
  84. {
  85. if (SPP::edit(['status' => intval($st)], $id))
  86. return JsonService::successful('操作成功');
  87. else
  88. return JsonService::fail('操作失败');
  89. }
  90. }