Shops.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 app\common\mode\ShopDelivery;
  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 delivery(UserEnterLog $userEnterLog){
  40. }
  41. //添加记录
  42. public function create(UserEnterLog $userEnterLog)
  43. {
  44. $data = $this->request->post();
  45. $result = false;
  46. try {
  47. validate(ShopValidate::class)->scene('add')->check($data);
  48. $data['user_id'] = $this->userinfo['id'];
  49. $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
  50. $result = $userEnterLog::create($data);
  51. }catch (ValidateException $e) {
  52. return $this->error($e->getError());
  53. } catch (\Exception $e) {
  54. $this->error($e->getMessage());
  55. }
  56. if ($result === false) {
  57. $this->error(__('没有新增任何数据'));
  58. }
  59. $this->success();
  60. }
  61. }