Shops.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. return $this->success('ok', json_decode($shopList->where('id', $shop_id)->value('type_spec'), true));
  35. }
  36. //添加记录
  37. public function create(UserEnterLog $userEnterLog)
  38. {
  39. $data = $this->request->post();
  40. $result = false;
  41. try {
  42. validate(ShopValidate::class)->scene('add')->check($data);
  43. $data['user_id'] = $this->userinfo['id'];
  44. $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
  45. $result = $userEnterLog::create($data);
  46. }catch (ValidateException $e) {
  47. return $this->error($e->getError());
  48. } catch (\Exception $e) {
  49. $this->error($e->getMessage());
  50. }
  51. if ($result === false) {
  52. $this->error(__('没有新增任何数据'));
  53. }
  54. $this->success();
  55. }
  56. }