1557492053 3 lat temu
rodzic
commit
10fa202bf3

+ 16 - 1
app/api/controller/Customer.php

@@ -40,7 +40,22 @@ class Customer extends \app\BaseController
         return $this->ok($res->data);
     }
 
-
+    /**
+     * @return \think\response\Json
+     * @throws \app\exception\BaseException
+     */
+    public function getCustomer() {
+        $params = $this->request->param();
+        if(!isset($params['name']) && !isset($params['mobile']) && !isset($params['customer_id']))
+            predicate(false, '搜索条件必须存在一个');
+        $res = $this->service->getCustomer(
+            isset($params['customer_id']) ? format_string($params['customer_id']) : null,
+            isset($params['name']) ? format_string($params['name']) : null,
+            isset($params['mobile']) ? format_string($params['mobile']) : null
+        );
+        predicate($res->bool, $res->message);
+        return $this->ok($res->data);
+    }
 
 
 

+ 73 - 1
app/api/controller/Order.php

@@ -81,6 +81,78 @@ class Order extends \app\BaseController
         return $this->ok($res->data);
     }
 
+    /**
+     * @return \think\response\Json
+     * @throws BaseException
+     */
+    public function fetch() {
+        $params = $this->request->param();
+        predicate(isset($params['store_id']) && $params['store_id'] > 0, '门店id不能为空');
+        predicate(isset($params['type']) && in_array($params['type'], [1, 2]), '订单类型不符合规则');
+        $res = $this->service->fetch($params);
+        return $this->ok($res);
+    }
+
+    /**
+     * @return \think\response\Json
+     * @throws BaseException
+     */
+    public function fetchByCustomerId() {
+        $params = $this->request->param();
+        predicate(isset($params['store_id']) && $params['store_id'] > 0, '门店id不能为空');
+        predicate(isset($params['customer_id']) && $params['customer_id'] > 0, '客户ID不能为空');
+        $res = $this->service->fetchByCustomerId($params);
+        return $this->ok($res);
+    }
+
+    /**
+     * @return \think\response\Json
+     * @throws BaseException
+     */
+    public function upload_numerology() {
+        $params = $this->request->param();
+        predicate(isset($params['order_product_id']) && $params['order_product_id'] > 0, '订单商品不能空!');
+        predicate(isset($params['report']), '命理报告不能为空');
+        $res = $this->service->upload_numerology($params['order_product_id'], $params['report']);
+        predicate($res->bool,$res->message);
+        return $this->ok($res->data);
+    }
+
+
+
+
+
+
+
+
+
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
 
-}

+ 12 - 0
app/api/controller/Product.php

@@ -31,4 +31,16 @@ class Product extends BaseController
         return $this->ok($res);
     }
 
+
+    /**
+     * @return \think\response\Json
+     */
+    public function upload() {
+        // 获取表单上传文件 例如上传了001.jpg
+        $file = request()->file('file');
+        // 上传到本地服务器
+        $save_name = \think\facade\Filesystem::disk('public')->putFile( 'numerology', $file);
+        return $this->ok(str_replace('\\',"/",'/storage/'.$save_name));
+    }
+
 }

+ 1 - 0
app/api/lang/zh-cn.php

@@ -45,6 +45,7 @@ return [
     "The Adviser|Teacher does not exist"    =>  "顾问或者老师不存在!",
     "Stores do not exist"           =>  "门店不存在",
     "inventory shortage"            =>  "库存不足",
+    "No customer found"             =>  "未找到客户",
 ];
 
 

+ 5 - 1
app/api/route/app.php

@@ -5,7 +5,7 @@ use think\facade\Route;
 
 Route::post('api/login','api/login/login');
 
-
+Route::rule('api/upload','api/product/upload');
 
 Route::group('api/product', function () {
     Route::rule('search', 'api/product/search');
@@ -14,6 +14,7 @@ Route::group('api/product', function () {
 
 Route::group('api/customer', function () {
     Route::rule('add', 'api/customer/add');
+    Route::rule('get', 'api/customer/getCustomer');
 })->middleware(\app\common\middleware\VerifySessionToken::class);
 
 Route::group('api/user', function () {
@@ -25,6 +26,9 @@ Route::group('api/user', function () {
 Route::group('api/order', function () {
     Route::rule('create', 'api/order/create');
     Route::rule('payment', 'api/order/payment');
+    Route::rule('fetch', 'api/order/fetch');
+    Route::rule('fetchByCustomerId', 'api/order/fetchByCustomerId');
+    Route::rule('upload_numerology', 'api/order/upload_numerology');
 })->middleware(\app\common\middleware\VerifySessionToken::class);
 
 Route::group('api/payment', function () {

+ 33 - 0
app/api/service/AuthService.php

@@ -0,0 +1,33 @@
+<?php
+
+
+namespace app\api\service;
+
+
+use app\common\model\AdminModel;
+
+class AuthService extends \app\BaseService
+{
+
+//    private $adminModel;
+//
+//    public function __construct()
+//    {
+//        $this->adminModel = new AdminModel();
+//    }
+
+    public static function is_look_all($admin_id, $data_rule_id) {
+        $admin = (new AdminModel())->findById($admin_id);
+        if(!$admin || !$admin->access || !$admin->access->group) return false;
+        return in_array($data_rule_id,$admin->access->group->data_rules ? explode(',', $admin->access->group->data_rules) : []);
+    }
+
+
+
+
+
+
+
+
+
+}

+ 106 - 1
app/api/service/CustomerService.php

@@ -6,6 +6,9 @@ use app\BaseService;
 use app\common\model\AdminModel;
 use app\common\model\CustomerModel;
 use app\common\model\CustomerZueCoinModel;
+use app\common\model\OrderAnnualFeeModel;
+use app\common\model\OrderModel;
+use app\common\model\OrderProductModel;
 use app\common\model\StoreModel;
 use app\common\model\ZueCoinRecordModel;
 
@@ -14,6 +17,9 @@ class CustomerService extends BaseService
     private $customerModel;
     private $adminModel;
     private $storeModel;
+    private $orderModel;
+    private $orderProductModel;
+    private $orderAnnualFeeModel;
     private $customerZueCoinModel;
     private $zueCoinRecordModel;
 
@@ -22,6 +28,9 @@ class CustomerService extends BaseService
         $this->customerModel = new CustomerModel();
         $this->adminModel = new AdminModel();
         $this->storeModel = new StoreModel();
+        $this->orderModel = new OrderModel();
+        $this->orderAnnualFeeModel = new OrderAnnualFeeModel();
+        $this->orderProductModel = new OrderProductModel();
         $this->customerZueCoinModel = new CustomerZueCoinModel();
         $this->zueCoinRecordModel = new ZueCoinRecordModel();
     }
@@ -70,4 +79,100 @@ class CustomerService extends BaseService
         }
         return $this->ok($customer->id);
     }
-}
+
+
+    public function getCustomer($customer_id = null, $name = null, $mobile = null) {
+        if($customer_id > 0) {
+            $customer = $this->customerModel->findById($customer_id);
+        } else if ($name) {
+            $customer = $this->customerModel->findByName($name);
+        } else {
+            $customer = $this->customerModel->findByMobile($mobile);
+        }
+        if (!$customer) return $this->fail(lang('No customer found'));
+        $orders = $this->orderModel->fetchOrderByCustomerId($customer->id);
+
+        //订单总额
+        $total_receivable_amount = 0;
+        //订单总数
+        $total_order_num = count($orders);
+        //待收取定金
+        $total_wait_gather_earnest_amount = 0;
+        //已上传报告数
+        $total_upload_report = 0;
+        //未上传报告数
+        $total_wait_upload_report = 0;
+        $order_ids = [];
+        foreach ($orders as $order) {
+            array_push($order_ids, $order['id']);
+            $total_receivable_amount += $order['receivable_amount'];
+            $total_wait_gather_earnest_amount += $order['imposed_amount'];
+        }
+
+        $order_annuals = $this->orderAnnualFeeModel->fetchByOrderIds($order_ids);
+        // 待收取年费
+        $total_wait_gather_annual_fee = array_reduce($order_annuals, function ($result, $item) {
+            $result += $item['fee'];
+            return $result;
+        },0);
+
+        $customer['total'] = [
+            'total_receivable_amount' => $total_receivable_amount,
+            'total_order_num' => $total_order_num,
+            'total_wait_gather_annual_fee' => $total_wait_gather_annual_fee,
+            'total_wait_gather_earnest_amount' => $total_wait_gather_earnest_amount,
+            'total_wait_upload_report' => "{$this->orderProductModel->countByCustomerId($customer_id,1,1)}/{$this->orderProductModel->countByCustomerId($customer_id,1)}"
+        ];
+        return  $this->ok($customer);
+    }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 55 - 3
app/api/service/OrderService.php

@@ -18,7 +18,6 @@ use app\common\model\PaymentChannelModel;
 use app\common\model\ProductModel;
 use app\common\model\StoreModel;
 use app\common\model\StoreProductModel;
-use think\cache\driver\Redis;
 use think\facade\Db;
 
 class OrderService extends \app\BaseService
@@ -131,13 +130,18 @@ class OrderService extends \app\BaseService
         // 总消费税
         $total_sales_tax = 0;
         $advisor_1_ids = [];
+        $product_names = [];
+        $order_no = $this->orderModel->genOrderNo($store->id, $store->abbr);
         for ($i = 0; $i < count($store_products_params); $i++) {
             $store_products_param = $store_products_params[$i];
             $store_product = $fmt_store_products[$store_products_param->store_product_id];
             array_push($advisor_1_ids, $store_products_param->adviser_1_id);
             for ($j = 0; $j < $store_products_param->quantity; $j++) {
+                array_push($product_names, $store_product['product']['name']);
                 array_push($order_products, [
                     'order_id' => 0,
+                    'order_no' => $order_no,
+                    'customer_id' => $customer->id,
                     'product_id' => $store_product['product']['id'],
                     'store_product_id' => $store_product['id'],
                     'product_name' => $store_product['product']['name'],
@@ -167,9 +171,10 @@ class OrderService extends \app\BaseService
             }
         }
         $order = $this->orderModel->create([
-            'no' => $this->orderModel->genOrderNo($store->id, $store->abbr),
+            'no' => $order_no,
             'customer_id' => $customer->id,
             'customer_name' => $customer->name_en,
+            'obj_names' =>  join(',',array_unique($product_names)),
             'rental_amount' => $rental_amount,
             'receivable_amount' =>  $rental_amount,
             'receive_amount'    =>  0,
@@ -352,7 +357,7 @@ class OrderService extends \app\BaseService
                 'service_charge_amount' =>  $order->service_charge_amount + $service_charge,
             ];
             if (round($receive_amount) == round($imposed_amount)) { // 支付满了
-                $update_order['type'] = 2;
+                $update_order['type'] = 1;
                 Db::table('erp_order_product')->where('order_id', $order->id)->update(['is_pay' => 1]);
                 if(count($order_annual_fees) > 0) {
                     Db::table('erp_order_annual_fee')->insertAll($order_annual_fees);
@@ -399,6 +404,53 @@ class OrderService extends \app\BaseService
         return $this->ok(true);
     }
 
+
+    public function fetch($params) {
+        $is_look_all = AuthService::is_look_all($params['admin_id'],$params['type'] == 1 ? 10003 : 10004);
+        $res = $this->orderModel->search($params, $is_look_all);
+        $items = $res['data'];
+        foreach ($items as &$item) {
+            $item['is_need_upload'] = $item['type'] == 1 && in_array(true, array_map(function ($product) {
+                return $product['is_upload_numerology'] == 1 && $product['is_upload'] == 0;
+            }, $item['products']));
+        }
+        return [$items, $res['total']];
+    }
+
+    /**
+     * @param $params
+     * @return array
+     * @throws \think\db\exception\DbException
+     */
+    public function fetchByCustomerId($params) {
+        $res = $this->orderModel->fetchByCustomerId($params['customer_id'], $params['page'] ?? 1, $params['size'] ?? 20);
+        $items = $res['data'];
+        foreach ($items as &$item) {
+            $item['is_need_upload'] = $item['type'] == 1 && in_array(true, array_map(function ($product) {
+                    return $product['is_upload_numerology'] == 1 && $product['is_upload'] == 0;
+                }, $item['products']));
+        }
+        return [$items, $res['total']];
+    }
+
+
+
+    public function upload_numerology($order_product_id, $report) {
+        $order_product = $this->orderProductModel->findById($order_product_id);
+        if (!$order_product) return $this->fail('订单商品不存在,无法上传命理报告!');
+        if (!$order_product->is_pay) return $this->fail('订单未支付,无法上传商品');
+        $order_product->is_upload = 1;
+        $order_product->report = $report;
+        $order_product->save();
+        return $this->ok($order_product);
+    }
+
+
+
+
+
+
+
 }
 
 

+ 17 - 0
app/api/validate/SearchOrderValidate.php

@@ -0,0 +1,17 @@
+<?php
+
+
+namespace app\api\validate;
+
+
+class SearchOrderValidate extends \app\common\validate\BaseValidate
+{
+    protected $rule = [
+        'store_id'  => 'require|number',
+        'type'  => 'require',
+    ];
+
+
+
+
+}

+ 4 - 0
app/common/middleware/VerifySign.php

@@ -22,6 +22,10 @@ class VerifySign
         $is_open = true;
         if(!$is_open || (isset($params['__TEST__']) && $params['__TEST__'] == __TEST__))
             return $next($request);
+        $has_upload = strpos($request->url(),'api/upload');
+        if($has_upload !== false && $has_upload >= 0) {
+            return $next($request);
+        }
         predicate(isset($params['sign']),'sign err');
         $sign = $this->signature($params);
         predicate($sign == $params['sign'],'verify sign err');

+ 16 - 0
app/common/model/CustomerModel.php

@@ -49,4 +49,20 @@ class CustomerModel extends BaseModel
     }
 
 
+
+    public function findByName($name) {
+        return $this->where([
+            ['is_delete','=', 0],
+            ['name_zh|name_en', '=', $name]
+        ])->find();
+    }
+
+    public function findByMobile($mobile) {
+        return $this->where([
+            ['is_delete','=', 0],
+            ['mobile', '=', $mobile]
+        ])->find();
+    }
+
+
 }

+ 8 - 0
app/common/model/OrderAnnualFeeModel.php

@@ -13,4 +13,12 @@ class OrderAnnualFeeModel extends BaseModel
     {
         // TODO: Implement genSchema() method.
     }
+
+    public function fetchByOrderIds($order_ids, $is_pay = 0) {
+        return $this->where('is_delete', 0)
+            ->where('order_id', 'in', $order_ids)
+            ->where('is_pay', '=', $is_pay)
+            ->select()->toArray();
+    }
+
 }

+ 66 - 1
app/common/model/OrderModel.php

@@ -50,9 +50,10 @@ class OrderModel extends BaseModel
             array_push($where,['type', '=', $params['type']]);
         return $this->where($where)
             ->with(['products','store'])
-            ->order('create_time','desc')
+            ->order('update_time','desc')
             ->paginate(['list_rows'=>10, "query" => $params]);
     }
+
     public function report(array $params) {
         $where = [
             ['is_delete', '=', 0]
@@ -80,4 +81,68 @@ class OrderModel extends BaseModel
             ])->find($id);
     }
 
+    /**
+     * @param $params
+     * @param bool $is_look_all
+     * @return array
+     * @throws \think\db\exception\DbException
+     */
+    public function search($params, $is_look_all = false) {
+        $where = [
+            ['is_delete', '=', 0],
+            ['type', '=', $params['type']],
+            ['store_id', '=', $params['store_id']],
+        ];
+        if (isset($params['order_no']) && strlen($params['order_no']) > 0)
+            array_push($where, ['no', 'like', '%'.$params['order_no'].'%']);
+        if (isset($params['start_time']) && $params['start_time'] > 0)
+            array_push($where, ['create_time', '>=', $params['start_time']]);
+        if (isset($params['end_time'])  && $params['end_time'] > 0)
+            array_push($where, ['create_time', '<=', $params['end_time']]);
+        if (isset($params['obj_name']) && strlen($params['obj_name']) > 0)
+            array_push($where, ['obj_names', 'like', '%'.$params['obj_name'].'%']);
+        $query = $this->where($where)
+            ->with(['products']);
+        if (isset($params['advisor_id']))
+            $query->where("FIND_IN_SET('{$params['advisor_id']}', advisor_ids)");
+        if (!$is_look_all) {
+            $query->where("FIND_IN_SET('{$params['admin_id']}', advisor_ids)");
+        }
+        return $query->order('update_time', 'desc')
+            ->page($params['page'] ?? 1)
+            ->paginate($params['size'] ?? 10)->toArray();
+    }
+
+    public function fetchOrderByCustomerId($c_id) {
+        return $this->where([
+            ['is_delete', '=', 0],
+            ['customer_id', '=', $c_id]
+        ])->select()->toArray();
+    }
+
+    /**
+     * @param $customer_id
+     * @param int $page
+     * @param int $size
+     * @return array
+     * @throws \think\db\exception\DbException
+     */
+    public function fetchByCustomerId($customer_id, $page = 1, $size = 10) {
+        return $this->where([
+            ['is_delete', '=', 0],
+            ['customer_id', '=', $customer_id]
+        ])->with(['products'])->order('update_time', 'desc')->page($page)->paginate($size)->toArray();
+    }
+
+
+
+
+
+
+
+
+
+
+
+
 }

+ 26 - 0
app/common/model/OrderProductModel.php

@@ -13,12 +13,38 @@ class OrderProductModel extends BaseModel
         // TODO: Implement genSchema() method.
     }
 
+    /**
+     * @param $o_id
+     * @return OrderProductModel[]|array|\think\Collection
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
     public function findByOrderId($o_id) {
         return $this->where('is_delete', 0)
             ->where('order_id',$o_id)
             ->select();
     }
 
+    /**
+     * @param $c_id
+     * @param int $is_upload_numerology
+     * @param int $is_upload
+     * @return int
+     * @throws \think\db\exception\DbException
+     */
+    public function countByCustomerId($c_id, $is_upload_numerology = 1, $is_upload = null) {
+        $where = [
+            ['is_delete', '=', 0],
+            ['customer_id', '=', $c_id],
+            ['is_upload_numerology', '=', $is_upload_numerology]
+        ];
+        if ($is_upload) {
+            array_push($where,['is_upload', '=', $is_upload]);
+        }
+        return $this->where($where)
+            ->count();
+    }
 
 
 

BIN
public/storage/numerology/20221228/6c8b8c2b34d1ab0645178c4bfaefb483.jpg


BIN
public/storage/numerology/20221228/8c556c5b8c9285c6b769aeb6800a401e.jpg


BIN
public/storage/numerology/20221228/f1fafaf9ab984e82920fdfe3601f8f7f.jpg


BIN
public/storage/numerology/20221228/f2905de32e63016bb37e5094adc68122.jpg