|
|
@@ -2,13 +2,13 @@
|
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
-use app\common\model\ApiUser;
|
|
|
-use app\common\model\Orders;
|
|
|
+use app\common\model\UserEnterLog;
|
|
|
+use app\api\validate\Shop as ShopValidate;
|
|
|
use app\common\model\ShopList;
|
|
|
use think\facade\Db;
|
|
|
use think\Exception;
|
|
|
use think\facade\Request;
|
|
|
-use think\Log;
|
|
|
+use think\exception\ValidateException;
|
|
|
|
|
|
class Shops extends Base
|
|
|
{
|
|
|
@@ -47,29 +47,30 @@ class Shops extends Base
|
|
|
}
|
|
|
|
|
|
|
|
|
- function doCurlPostRequest($url = '',Array $data = array())
|
|
|
+ //添加记录
|
|
|
+ public function create(UserEnterLog $userEnterLog)
|
|
|
{
|
|
|
- $data_string = json_encode($data,JSON_UNESCAPED_UNICODE);
|
|
|
- // $data_string = $data;
|
|
|
- $curl_con = curl_init();
|
|
|
- curl_setopt($curl_con, CURLOPT_URL,$url);
|
|
|
- curl_setopt($curl_con, CURLOPT_HEADER, false);
|
|
|
- curl_setopt($curl_con, CURLOPT_POST, true);
|
|
|
- curl_setopt($curl_con, CURLOPT_RETURNTRANSFER, TRUE);
|
|
|
- curl_setopt($curl_con, CURLOPT_CONNECTTIMEOUT, 5);
|
|
|
- curl_setopt($curl_con, CURLOPT_HTTPHEADER, array(
|
|
|
- 'Content-Type: application/json',
|
|
|
- 'Content-Length: ' . strlen($data_string))
|
|
|
- );
|
|
|
- curl_setopt($curl_con, CURLOPT_POSTFIELDS, $data_string);
|
|
|
- $res = curl_exec($curl_con);
|
|
|
- $status = curl_getinfo($curl_con);
|
|
|
- curl_close($curl_con);
|
|
|
+
|
|
|
+ $data = $this->request->post();
|
|
|
+ $result = false;
|
|
|
+ try {
|
|
|
+ validate(ShopValidate::class)->scene('add')->check($data);
|
|
|
|
|
|
- if (isset($status['http_code']) && $status['http_code'] == 200) {
|
|
|
- return $res;
|
|
|
- } else {
|
|
|
- return FALSE;
|
|
|
+ $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();
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|