| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace app\api\controller;
- use app\common\model\UserEnterLog;
- use app\api\validate\Shop as ShopValidate;
- use app\common\model\ShopList;
- use app\common\model\ShopDelivery;
- use think\Exception;
- use think\facade\Cache;
- use think\exception\ValidateException;
- class Shops extends Base
- {
- //protected $noNeedLogin = ['*'];
- /**
- * @return void 全部平台
- */
- public function getPlatform(){
- $list = site_config('addonsd.platform_list');
- $this->success('提交成功', $list);
- }
- //获取店铺
- public function getShop(ShopList $shopList){
-
- $platform_id = $this->request->post('platform_id/d');
- if(empty($platform_id)){
- $this->error('参数有误');
- }
- return $this->success('ok', $shopList->where('platform', $platform_id)->column('name', 'id'));
- }
- //获取规格
- public function getSpec(ShopList $shopList){
- $shop_id = $this->request->post('shop_id/d');
- if( empty($shop_id)){
- $this->error('参数有误');
- }
- $spec = $shopList->where('id', $shop_id)->value('type_spec');
- $shopList = $spec?json_decode($spec, true): [];
- return $this->success('ok', $shopList);
- }
- //发货记录
- public function delivery(ShopDelivery $shopDelivery){
- $data = $this->request->post();
- $result = false;
- try {
- validate(ShopValidate::class)->scene('add')->check($data);
-
- $data['user_id'] = $this->userinfo['id'];
- $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
- $result = $shopDelivery::create($data);
-
- }catch (ValidateException $e) {
- return $this->error($e->getError());
- } catch (\Exception $e) {
- $this->error($e->getMessage());
- }
- if ($result === false) {
- $this->error(__('没有新增任何数据'));
- }
- $this->success();
- }
- //添加记录
- public function create(UserEnterLog $userEnterLog)
- {
-
- $data = $this->request->post();
- $result = false;
- try {
- validate(ShopValidate::class)->scene('add')->check($data);
-
- $data['user_id'] = $this->userinfo['id'];
- $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
- $result = $userEnterLog::create($data);
-
- }catch (ValidateException $e) {
- return $this->error($e->getError());
- } catch (\Exception $e) {
- $this->error($e->getMessage());
- }
- if ($result === false) {
- $this->error(__('没有新增任何数据'));
- }
- $this->success();
- }
-
- }
|