Browse Source

fix():修改配置

geek 4 years ago
parent
commit
2d9a5fc6b0

+ 15 - 0
application/api/controller/Order.php

@@ -324,6 +324,21 @@ class Order extends BaseController {
             'encode' => $this->request->header('serchkey')]);
     }
 
+    public function changeCode() {
+        $input = Until::getInput();
+        $rule = [
+            'orderId|订单号' => 'require',
+        ];
+        Until::check($rule, $input);
+        $ser  = new OrderService();
+        $code = $ser->changeCode();
+        $wModel = new WriteOffModel();
+        $wModel::where(['order_id' => $input['orderId']])->update([
+            'write_off_code' => $code,
+            'over_time' => date('Y-m-d  H:i:s', time() + 5 * 60),
+        ]);
+        Until::output(['code' => $code]);
+    }
 
     /**
      * @OA\Get(path="/api/Order/writeOffOrder",

+ 25 - 30
application/api/controller/Pay.php

@@ -40,19 +40,20 @@ class Pay extends BaseController {
         if ($this->isAdmin()) {
             $where = [];
         } else {
-            $where[] = ['p.status', '=', $model::NORMAL];
+            $where[] = ['status', '=', $model::NORMAL];
         }
 
         if (!empty($input['code'])) {
-            $where[] = ['p.pay_code', 'like', "%{$input['code']}%"];
+            $where[] = ['pay_code', 'like', "%{$input['code']}%"];
         }
 
-        if (!empty($input['groupId'])) {
-            $where[] = ['p.group_id', '=', "{$input['groupId']}"];
-        }
-        $where[] = ['gr.admin_id','=',$this->adminId];
+//        if (!empty($input['groupId'])) {
+//            $where[] = ['p.group_id', '=', "{$input['groupId']}"];
+//        }
+//        $where[] = ['gr.admin_id','=',$this->adminId];
+
         $model->setWhere($where);
-        $data = $model->getPayList();
+        $data = $model->getPageList($model);
         Until::output($data);
     }
 
@@ -67,15 +68,9 @@ class Pay extends BaseController {
      *       mediaType="multipart/form-data",
      *         @OA\Schema(
      *           @OA\Property(description="支付code", property="code", type="string", default="jj公司"),
-     *           @OA\Property(description="集团id", property="groupId", type="integer", default="1"),
-     *           @OA\Property(description="主商户号", property="masterPayId", type="string", default="a01"),
-     *           @OA\Property(description="子商户号", property="subPayId", type="string", default="1"),
-     *           @OA\Property(description="主appId", property="masterAppId", type="string", default="1"),
-     *           @OA\Property(description="子appId", property="subAppId", type="string", default="1"),
-     *           @OA\Property(description="秘钥", property="xcxSecret", type="string", default="1"),
      *           @OA\Property(description="状态 1正常  2删除", property="status", type="integer", default="1"),
      *           @OA\Property(description="备注", property="remark", type="dtring", default="xx支付"),
-     *           required={"code","groupId","masterPayId","masterAppId","xcxSecret"})
+     *           required={"code"})
      *       )
      *     ),
      *   @OA\Response(response="200", description="请求成功")
@@ -85,12 +80,12 @@ class Pay extends BaseController {
         $input = Until::getInput();
         $rule = [
             'code|支付code'        => 'require',
-            'masterPayId|主商户号'   => 'require',
+//            'masterPayId|主商户号'   => 'require',
             //'subPayId|子商户号'  => 'require',
-            'masterAppId|主appId' => 'require',
+//            'masterAppId|主appId' => 'require',
             //'subAppId|子appId'  => 'require',
-            'groupId|集团id'       => 'require',
-            'xcxSecret|秘钥'       => 'require',
+//            'groupId|集团id'       => 'require',
+//            'xcxSecret|秘钥'       => 'require',
         ];
         Until::check($rule, $input);
         $model = new PayModel();
@@ -98,24 +93,24 @@ class Pay extends BaseController {
             $id = (int)$input['id'];
             $model::where(['id' => $id])->update([
                 'pay_code'      => $input['code'],
-                'master_pay_id' => $input['masterPayId'],
-                'sub_pay_id'    => $input['subPayId'],
-                'master_app_id' => $input['masterAppId'],
-                'sub_app_id'    => $input['subAppId'],
-                'xcx_secret'    => $input['xcxSecret'],
-                'group_id'      => $input['groupId'],
+//                'master_pay_id' => $input['masterPayId'],
+//                'sub_pay_id'    => $input['subPayId'],
+//                'master_app_id' => $input['masterAppId'],
+//                'sub_app_id'    => $input['subAppId'],
+//                'xcx_secret'    => $input['xcxSecret'],
+//                'group_id'      => $input['groupId'],
                 'status'        => $input['status'] ?? 1,
                 'remark'        => $input['remark']
             ]);
         } else {
             $id = $model->insertGetId([
                 'pay_code'      => $input['code'],
-                'master_pay_id' => $input['masterPayId'],
-                'sub_pay_id'    => $input['subPayId'] ?? "",
-                'master_app_id' => $input['masterAppId'],
-                'sub_app_id'    => $input['subAppId'] ?? "",
-                'xcx_secret'    => $input['xcxSecret'],
-                'group_id'      => $input['groupId'],
+//                'master_pay_id' => $input['masterPayId'],
+//                'sub_pay_id'    => $input['subPayId'] ?? "",
+//                'master_app_id' => $input['masterAppId'],
+//                'sub_app_id'    => $input['subAppId'] ?? "",
+//                'xcx_secret'    => $input['xcxSecret'],
+//                'group_id'      => $input['groupId'],
                 'status'        => $input['status'] ?? 1,
                 'remark'        => $input['remark'] ?? ''
             ]);

+ 5 - 3
application/api/controller/Product.php

@@ -87,7 +87,9 @@ class Product extends BaseController {
         $model = new ProductModel();
         $model->setPage($input['page'] ?? 1);
         $model->setPageSize($input['pageSize'] ?? 10);
-        $model->setWhere(['status' => 1]);
+        if (!$this->isAdmin()) {
+            $model->setWhere(['status' => 1]);
+        }
         $data = $model->getProductTypeList();
         foreach ($data['list'] as &$v) {
             $v['title'] = $v['product_type_name'];
@@ -132,7 +134,7 @@ class Product extends BaseController {
                 'product_type_img'     => $input['imgUrl'],
             ]);
         }
-        Until::output();
+        Until::output(['isSuccess' => 1]);
     }
 
     /**
@@ -195,7 +197,7 @@ class Product extends BaseController {
             'companyId|公司id'      => 'require',
             'brandId|品牌id'        => 'require',
             'productContent|产品内容' => 'require',
-            'productType|产品类型'    => 'require'
+            'productTypeId|产品类型'    => 'require'
         ];
         Until::check($rule, $input);
         $model = new ProductModel();

+ 6 - 2
application/api/controller/Store.php

@@ -44,6 +44,10 @@ class Store extends BaseController {
         if (!empty($input['status'])) {
             $where[] = ['s.status', '=', $input['status']];
         }
+
+        if (!$this->isAdmin()) {
+            $where[] = ['s.status', '=', 1];
+        }
         if (!empty($input['name'])) {
             $where[] = ['s.store_name', 'like', "%{$input['name']}%"];
         }
@@ -72,7 +76,7 @@ class Store extends BaseController {
         foreach ($data['list'] as &$info) {
             if (!empty($info['distance'])) {
                 $info['distanceA'] = $info['distance'];
-                $info['distance'] = number_format($info['distance'], 2) . "KM";
+                $info['distance'] = number_format($info['distance'], 2) . "km";
             }
         }
         unset($info);
@@ -253,7 +257,7 @@ class Store extends BaseController {
         $storeScore = $disModel::where(['store_id' => $info['id']])->avg('store_score');
         $info['score'] = (int)$storeScore;
         $distance = (float)(substr(($info['distance'] / 1000), 0, 6));
-        $info['distance'] = number_format($distance, 2) . "KM";
+        $info['distance'] = number_format($distance, 2) . "km";
         Until::output(['info' => Until::modelToArray($info)]);
     }
 

+ 6 - 3
application/api/model/OrderModel.php

@@ -25,15 +25,18 @@ class OrderModel  extends BaseModel {
             ->join('store store', 'store.id = o.store_id','left')
             ->join('staff staff', 'staff.id = o.staff_id','left')
             ->join('write_off wo', 'wo.order_id = o.id','left')
+            ->join('user u','u.id = o.user_id','left')
             ->join('discuss_order discussOrder','discussOrder.order_id = o.id and discussOrder.user_id = o.user_id','left');
         $selectModel = $this->alias('o')
             ->field('o.*,store.store_name,store.address,discussOrder.id as discussId,staff.staff_name,wo.write_off_code,
-            wo.write_off_status,wo.write_off_time,staff.id as writeOffAdminId,
-            p.product_name,p.product_img')
+            wo.write_off_status,wo.write_off_time,staff.id as writeOffAdminId,wo.over_time as  writeOffOverTime,
+            p.product_name,p.product_img,
+            u.name as userName')
             ->join('store store', 'store.id = o.store_id','left')
             ->join('staff staff', 'staff.id = o.staff_id','left')
             ->join('product p', 'p.id = o.product_id','left')
             ->join('write_off wo', 'wo.order_id = o.id','left')
+            ->join('user u','u.id = o.user_id','left')
             ->join('discuss_order discussOrder','discussOrder.order_id = o.id and discussOrder.user_id = o.user_id','left')
             ->order('o.id desc');
         return $this->joinModelPageList($countModel, $selectModel);
@@ -44,7 +47,7 @@ class OrderModel  extends BaseModel {
     public function getOrderInfo() {
         $selectModel = $this->alias('o')
             ->field('o.*,store.store_name,store.address,discussOrder.id as discussId,staff.staff_name,wo.write_off_code,
-            wo.write_off_status,wo.write_off_time,staff.id as writeOffAdminId,
+            wo.write_off_status,wo.write_off_time,staff.id as writeOffAdminId,wo.over_time as writeOffOverTime,wo.create_time as writeOffCreateTime,
             p.product_name,p.product_img,store.latitude,store.longitude')
             ->join('store store', 'store.id = o.store_id','left')
             ->join('staff staff', 'staff.id = o.staff_id','left')

+ 2 - 0
application/api/model/WriteOffModel.php

@@ -10,6 +10,8 @@ use app\common\until\Until;
 
 class WriteOffModel  extends BaseModel {
 
+    const NO_WRITE_OFF = 1;
+
     protected $table = 'write_off';
 
 }

+ 38 - 2
application/common/service/OrderService.php

@@ -105,12 +105,14 @@ class OrderService {
         if (empty($userInfo)) {
             throw new ApiException('无此用户');
         }
+        $paySn = Until::createSn();
+        $model::where(['id' => $orderId])->update(['pay_sn' => $paySn]);
         $otherData = [
             'openId'   => $userInfo['open_id'],
             'attach'   => 'storeId:'.$info['store_id'],
             'money'    => $info['order_money'] * $info['num'] * 100,
             'mark'     => '购买了'.$productInfo['product_name'] ?? '',
-            'orderId'  => $info['order_sn'],
+            'orderId'  => $paySn,
             'username' => $userInfo['name'],
             'payCode'  => strtoupper($this->userName),
         ];
@@ -129,14 +131,16 @@ class OrderService {
 
 
     public function getPayToken() {
+//        var_dump('获取token'.time());
         $key = 'payToken' . $this->userName;
         $token = Cache::get($key);
-        $token = '';
         if (empty($token)) {
             $token = $this->getAuthPay();
             Cache::set($key, $token,'7100');
+//            var_dump('接口获取token结束'.time());
             return $token;
         }
+//        var_dump('缓存获取token结束'.time());
         return $token;
     }
 
@@ -160,6 +164,7 @@ class OrderService {
     }
 
     public function createOrderForOther(array $data) {
+//        var_dump('start'.time());
         $client = new Client();
         $res = $client->request('Post',
             Config::get('domain')."api/supers/wx-pay/gateway-no-order", [
@@ -172,6 +177,7 @@ class OrderService {
         if ($info['code'] != 200) {
             throw new ApiException($info['msg']);
         }
+//        var_dump('end'.time());
         return $info['data'];
     }
 
@@ -182,6 +188,36 @@ class OrderService {
             return;
         }
         $model::where(['order_sn' => $orderSn])->update(['status' => 2,'pay_time' => date('Y-m-d H:i:s')]);
+        $model::where(['pay_sn' => $orderSn])->update(['status' => 2,'pay_time' => date('Y-m-d H:i:s')]);
+
+        $wModel = new WriteOffModel();
+        $code  = $this->changeCode();
+        $wModel::where(['order_id' => $rs['order_id']])->update([
+            'write_off_code' => $code,
+            'over_time' => date('Y-m-d  H:i:s', time() + 5 * 60),
+        ]);
+    }
+
+
+    public function changeCode() {
+        $wModel = new WriteOffModel();
+        $codeList = $wModel::where(['write_off_status' => WriteOffModel::NO_WRITE_OFF])->field('write_off_code')->select();
+        $codeList  = Until::modelToArray($codeList);
+
+        $codeArr = [];
+        foreach ($codeList as $v)  {
+            $codeArr[] = $v['write_off_code'];
+        }
+        $code = $this->makeUniqCode($codeArr);
+        return $code;
+    }
+
+    public function makeUniqCode(array $codeList) {
+        $code = random_int(10000, 99999);
+        if (in_array($code, $codeList)) {
+            $this->makeUniqCode($codeList);
+        }
+        return $code;
     }
 
 }