Shops.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\model\ShopDelivery;
  7. use think\Exception;
  8. use think\facade\Cache;
  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(ShopDelivery $shopDelivery){
  40. $data = $this->request->post();
  41. $result = false;
  42. try {
  43. validate(ShopValidate::class)->scene('add')->check($data);
  44. $data['user_id'] = $this->userinfo['id'];
  45. $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
  46. $result = $shopDelivery::create($data);
  47. }catch (ValidateException $e) {
  48. return $this->error($e->getError());
  49. } catch (\Exception $e) {
  50. $this->error($e->getMessage());
  51. }
  52. if ($result === false) {
  53. $this->error(__('没有新增任何数据'));
  54. }
  55. $this->success();
  56. }
  57. //添加记录
  58. public function create(UserEnterLog $userEnterLog)
  59. {
  60. $data = $this->request->post();
  61. $result = false;
  62. try {
  63. validate(ShopValidate::class)->scene('add')->check($data);
  64. $data['user_id'] = $this->userinfo['id'];
  65. $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
  66. $result = $userEnterLog::create($data);
  67. }catch (ValidateException $e) {
  68. return $this->error($e->getError());
  69. } catch (\Exception $e) {
  70. $this->error($e->getMessage());
  71. }
  72. if ($result === false) {
  73. $this->error(__('没有新增任何数据'));
  74. }
  75. $this->success();
  76. }
  77. }