Shops.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\UserEnterLog;
  4. use app\api\validate\Shop as ShopValidate;
  5. use app\common\model\ShopList;
  6. use think\facade\Db;
  7. use think\Exception;
  8. use think\facade\Request;
  9. use think\exception\ValidateException;
  10. class Shops extends Base
  11. {
  12. // protected $noNeedLogin = [''];
  13. /**
  14. * @return void 全部平台
  15. */
  16. public function getPlatform(){
  17. $list = site_config('addonsd.platform_list');
  18. $this->success('提交成功', $list);
  19. }
  20. //获取店铺
  21. public function getShop(ShopList $shopList){
  22. $platform_id = $this->request->post('platform_id/d');
  23. if(empty($platform_id)){
  24. $this->error('参数有误');
  25. }
  26. return $this->success('ok', $shopList->where('platform', $platform_id)->column('name', 'id'));
  27. }
  28. //获取规格
  29. public function getSpec(ShopList $shopList){
  30. $shop_id = $this->request->post('shop_id/d');
  31. if( empty($shop_id)){
  32. $this->error('参数有误');
  33. }
  34. $spec = $shopList->where('id', $shop_id)->value('type_spec');
  35. $shopList = $spec?json_decode($spec, true): [];
  36. return $this->success('ok', $shopList);
  37. }
  38. //添加记录
  39. public function create(UserEnterLog $userEnterLog)
  40. {
  41. $data = $this->request->post();
  42. $result = false;
  43. try {
  44. validate(ShopValidate::class)->scene('add')->check($data);
  45. $data['user_id'] = $this->userinfo['id'];
  46. $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
  47. $result = $userEnterLog::create($data);
  48. }catch (ValidateException $e) {
  49. return $this->error($e->getError());
  50. } catch (\Exception $e) {
  51. $this->error($e->getMessage());
  52. }
  53. if ($result === false) {
  54. $this->error(__('没有新增任何数据'));
  55. }
  56. $this->success();
  57. }
  58. }