Browse Source

一些功能

Kirin 3 years ago
parent
commit
909dc149c4

+ 4 - 0
app/admin/controller/user/User.php

@@ -333,6 +333,8 @@ class User extends AuthController
         $f[] = Form::input('card_id', '身份证号', $user->getData('card_id'));
         $f[] = Form::textarea('mark', '用户备注', $user->getData('mark'));
         $f[] = Form::radio('is_promoter', '推广员', $user->getData('is_promoter'))->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
+        $f[] = Form::radio('area_admin', '区域代理', $user->getData('area_admin'))->options([['value' => 0, 'label' => '无'], ['value' => 1, 'label' => '区代'], ['value' => 2, 'label' => '市代'], ['value' => 3, 'label' => '省代']]);
+        $f[] = Form::cityArea('area_address', '区域', $user->getData('area_province'), $user->getData('area_city'), $user->getData('area_district'));
         $f[] = Form::radio('status', '状态', $user->getData('status'))->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '锁定']]);
         $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('update', array('uid' => $uid)), 5);
         $this->assign(compact('form'));
@@ -353,6 +355,8 @@ class User extends AuthController
             ['integration_status', 0],
             ['integration', 0],
             ['status', 0],
+            ['area_admin']
+            ['area_address']
         ]);
         if (!$uid) return $this->failed('数据不存在');
         $user = UserModel::get($uid);

+ 12 - 0
app/admin/model/user/UserRecharge.php

@@ -173,4 +173,16 @@ class UserRecharge extends BaseModel
         ];
     }
 
+    public static function getStoreRechargeList($where)
+    {
+        $model = self::where('paid', 1);
+        if (isset($where['store_id']) && $where['store_id'] != '') {
+            $model = $model->where('store_id', $where['store_id']);
+        }
+        $sum = $model->sum('price');
+        $count = $model->count();
+        $list = $model->page((int)$where['page'], (int)$where['limit'])->order('pay_time', 'desc')->select();
+        return compact('sum', 'count', 'list');
+    }
+
 }

+ 25 - 1
app/api/controller/admin/StoreOrderController.php

@@ -6,6 +6,7 @@ use app\admin\model\system\SystemStoreBill;
 use app\admin\model\system\SystemStoreExtract;
 use app\admin\model\system\SystemStorePoint;
 use app\admin\model\system\SystemStoreProductStock;
+use app\admin\model\user\UserRecharge;
 use app\models\system\SystemStore;
 use app\Request;
 use think\db\exception\DataNotFoundException;
@@ -735,7 +736,7 @@ class StoreOrderController
             ['is_confirm', 0]
         ], $request, true);
         if (!$verify_code) return app('json')->fail('缺少核销码');
-        $orderInfo = StoreOrder::where('verify_code', $verify_code)->where('store_id', $storeStaff = SystemStoreStaff::where('uid', $uid)->value('store_id'))->where('paid', 1)->where('refund_status', 0)->find();
+        $orderInfo = StoreOrder::where('verify_code', $verify_code)->where('store_id', 'in', [SystemStoreStaff::where('uid', $uid)->value('store_id'), 0])->where('paid', 1)->where('refund_status', 0)->find();
         if (!$orderInfo) return app('json')->fail('核销的订单不存在于该门店或未支付或已退款');
         if ($orderInfo->status > 0) return app('json')->fail('订单已经核销');
         if ($orderInfo->combination_id && $orderInfo->pink_id) {
@@ -753,6 +754,14 @@ class StoreOrderController
                 $orderInfo->clerk_id = $storeStaff['id'];
             }
             $orderInfo->status = 2;
+            if ($orderInfo->store_id == 0) {
+                $orderInfo->store_id = SystemStoreStaff::where('uid', $uid)->value('store_id');
+                $store = SystemStore::get($orderInfo->store_id);
+                $orderInfo->province = explode(',', $store['address'])[0] ?? '';
+                $orderInfo->city = explode(',', $store['address'])[1] ?? '';
+                $orderInfo->district = explode(',', $store['address'])[2] ?? '';
+                SystemStore::decStock($orderInfo);
+            }
             if ($orderInfo->save()) {
                 OrderRepository::storeProductOrderTakeDeliveryAdmin($orderInfo);
                 StoreOrderStatus::status($orderInfo->id, 'take_delivery', '已核销');
@@ -772,4 +781,19 @@ class StoreOrderController
         }
     }
 
+    public function rechargeList(Request $request)
+    {
+        $uid = $request->uid();
+        $where = UtilService::getMore([
+            ['page', 1],
+            ['limit', 20],
+        ]);
+        $info = SystemStoreStaff::where('uid', $uid)->where('status', 1)->find();
+        if (!$info) {
+            return app('json')->fail('权限不足');
+        }
+        $where['store_id'] = $info['store_id'];
+        return app('json')->successful('ok', UserRecharge::getStoreRechargeList($where));
+    }
+
 }

+ 3 - 3
app/api/controller/order/StoreOrderController.php

@@ -164,9 +164,9 @@ class StoreOrderController
         $uid = $request->uid();
         if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
             return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
-        list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $integral_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId, $pointId) = UtilService::postMore([
+        list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $integral_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId, $pointId, $free_check) = UtilService::postMore([
             'addressId', 'couponId', 'payType', ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['integral_id', 0], ['formId', ''], ['bargainId', ''], ['from', 'weixin'],
-            ['shipping_type', 1], ['real_name', ''], ['phone', ''], ['store_id', 0], ['point_id', 0]
+            ['shipping_type', 1], ['real_name', ''], ['phone', ''], ['store_id', 0], ['point_id', 0], ['free_check', 0]
         ], $request, true);
         $payType = strtolower($payType);
         if ($bargainId) {
@@ -189,7 +189,7 @@ class StoreOrderController
             $isChannel = 0;
         elseif ($from == 'weixinh5')
             $isChannel = 2;
-        $order = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, $integral_id, false, $isChannel, $shipping_type, $real_name, $phone, $storeId, $pointId);
+        $order = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, $integral_id, false, $isChannel, $shipping_type, $real_name, $phone, $storeId, $pointId, 0, $free_check);
         if ($order === false) return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败'));
         $orderId = $order['order_id'];
         $info = compact('orderId', 'key');

+ 4 - 4
app/api/controller/user/UserRechargeController.php

@@ -25,7 +25,7 @@ class UserRechargeController
      */
     public function routine(Request $request)
     {
-        list($price, $recharId, $type) = UtilService::postMore([['price', 0], ['rechar_id', 0], ['type', 0]], $request, true);
+        list($price, $recharId, $type, $store_id) = UtilService::postMore([['price', 0], ['rechar_id', 0], ['type', 0], ['store_id', 0]], $request, true);
         if (!$price || $price <= 0) return app('json')->fail('参数错误');
         $storeMinRecharge = sys_config('store_user_min_recharge');
         if ($price < $storeMinRecharge) return app('json')->fail('充值金额不能低于' . $storeMinRecharge);
@@ -40,7 +40,7 @@ class UserRechargeController
                         $paid_price = $data['give_money'] ?? 0;
                     }
                 }
-                $rechargeOrder = UserRecharge::addRecharge($request->uid(), $price, 'routine', $paid_price);
+                $rechargeOrder = UserRecharge::addRecharge($request->uid(), $price, 'routine', $paid_price, 0, $store_id);
                 if (!$rechargeOrder) return app('json')->fail('充值订单生成失败!');
                 try {
                     return app('json')->successful(UserRecharge::jsPay($rechargeOrder));
@@ -68,7 +68,7 @@ class UserRechargeController
      */
     public function wechat(Request $request)
     {
-        list($price, $recharId, $from, $type) = UtilService::postMore([['price', 0], ['rechar_id', 0], ['from', 'weixin'], ['type', 0]], $request, true);
+        list($price, $recharId, $from, $type, $store_id) = UtilService::postMore([['price', 0], ['rechar_id', 0], ['from', 'weixin'], ['type', 0], ['store_id', 0]], $request, true);
         if (!$price || $price <= 0) return app('json')->fail('参数错误');
         $storeMinRecharge = sys_config('store_user_min_recharge');
         if ($price < $storeMinRecharge) return app('json')->fail('充值金额不能低于' . $storeMinRecharge);
@@ -83,7 +83,7 @@ class UserRechargeController
                         $paid_price = $data['give_money'] ?? 0;
                     }
                 }
-                $rechargeOrder = UserRecharge::addRecharge($request->uid(), $price, 'weixin', $paid_price);
+                $rechargeOrder = UserRecharge::addRecharge($request->uid(), $price, 'weixin', $paid_price, 0, $store_id);
                 if (!$rechargeOrder) return app('json')->fail('充值订单生成失败!');
                 try {
                     if ($from == 'weixinh5') {

+ 18 - 7
app/models/store/StoreOrder.php

@@ -20,9 +20,7 @@ use think\facade\Log;
 use app\models\system\SystemStore;
 use app\models\routine\RoutineTemplate;
 use app\models\user\{User, UserAddress, UserBill, UserSpread, WechatUser};
-use crmeb\services\{
-    SystemConfigService, WechatTemplateService, workerman\ChannelService
-};
+use crmeb\services\{OtherSMSService, SystemConfigService, WechatTemplateService, workerman\ChannelService};
 use crmeb\repositories\{
     GoodsRepository, PaymentRepositories, OrderRepository, ShortLetterRepositories, UserRepository
 };
@@ -277,7 +275,7 @@ class StoreOrder extends BaseModel
      * @throws \think\exception\DbException
      */
 
-    public static function cacheKeyCreateOrder($uid, $key, $addressId, $payType, $useIntegral = false, $couponId = 0, $mark = '', $combinationId = 0, $pinkId = 0, $seckill_id = 0, $bargain_id = 0, $integral_id = 0, $test = false, $isChannel = 0, $shipping_type = 1, $real_name = '', $phone = '', $storeId = 0, $pointId = 0, $store_order = 0)
+    public static function cacheKeyCreateOrder($uid, $key, $addressId, $payType, $useIntegral = false, $couponId = 0, $mark = '', $combinationId = 0, $pinkId = 0, $seckill_id = 0, $bargain_id = 0, $integral_id = 0, $test = false, $isChannel = 0, $shipping_type = 1, $real_name = '', $phone = '', $storeId = 0, $pointId = 0, $store_order = 0, $free_check = 0)
     {
         self::beginTrans();
         try {
@@ -376,7 +374,7 @@ class StoreOrder extends BaseModel
                 //门店自提没有邮费支付
                 $priceGroup['storePostage'] = 0;
                 $payPostage = 0;
-                if (!$pointId && !$test && !$store_order) {
+                if (!$pointId && !$test && !$store_order && !$free_check) {
                     return self::setErrorInfo('请选择自提点', true);
                 }
             }
@@ -465,12 +463,22 @@ class StoreOrder extends BaseModel
                 'deposit_back' => 0,
                 'deposit_status' => 0,
                 'store_order' => $store_order,
+                'province' => $addressInfo['province'],
+                'city' => $addressInfo['city'],
+                'district' => $addressInfo['district'],
             ];
             $orderInfo['store_id'] = SystemStore::getStoreDispose($storeId, 'id');
-            if (!$orderInfo['store_id']) return self::setErrorInfo('暂无门店无法选择门店!', true);
+            if (!$orderInfo['store_id'] && !$free_check) return self::setErrorInfo('暂无门店无法选择门店!', true);
+            else $orderInfo['store_id'] = 0;
+            if ($orderInfo['store_id']) {
+                $store = SystemStore::get($orderInfo['store_id']);
+                $orderInfo['province'] = explode(',', $store['address'])[0] ?? '';
+                $orderInfo['city'] = explode(',', $store['address'])[1] ?? '';
+                $orderInfo['district'] = explode(',', $store['address'])[2] ?? '';
+            }
             if ($shipping_type === 2) {
                 $orderInfo['verify_code'] = self::getStoreCode();
-                if (!$store_order) {
+                if (!$store_order && !$free_check) {
                     $orderInfo['point_id'] = SystemStorePoint::verificWhere()->where('store_id', $orderInfo['store_id'])->where('id', $pointId)->value('id');
                     if (!$orderInfo['point_id']) return self::setErrorInfo('找不到对应自提点!', true);
                 }
@@ -805,6 +813,9 @@ class StoreOrder extends BaseModel
         //支付成功后
         event('OrderPaySuccess', [$order, $formId]);
         $res = $res1 && $resPink && UserSpread::setSpreadSure($order['uid']) && User::backOrderBrokerage($order);
+        $user = User::getUserInfo($order['uid']);
+        if ($user['phone'])
+            OtherSMSService::send($user['phone'], '成功支付' . floatval(bcadd($order['pay_price'], $order['deposit'], 2)) . '元购买商品' . ($order['deposit'] ? "(含押金{$order['deposit']})" : ''));
         return false !== $res;
     }
 

+ 23 - 4
app/models/user/UserRecharge.php

@@ -7,8 +7,11 @@
 
 namespace app\models\user;
 
+use app\admin\model\system\SystemStoreBill;
+use app\models\system\SystemStore;
 use crmeb\basic\BaseModel;
 use crmeb\services\MiniProgramService;
+use crmeb\services\OtherSMSService;
 use crmeb\services\WechatService;
 use crmeb\traits\ModelTrait;
 
@@ -48,12 +51,12 @@ class UserRecharge extends BaseModel
      * @param int $paid
      * @return UserRecharge|bool|\think\Model
      */
-    public static function addRecharge($uid, $price, $recharge_type = 'weixin', $give_price = 0, $paid = 0)
+    public static function addRecharge($uid, $price, $recharge_type = 'weixin', $give_price = 0, $paid = 0, $store_id = 0)
     {
         $order_id = self::getNewOrderId($uid);
         if (!$order_id) return self::setErrorInfo('订单生成失败!');
         $add_time = time();
-        return self::create(compact('order_id', 'uid', 'price', 'recharge_type', 'paid', 'add_time', 'give_price'));
+        return self::create(compact('order_id', 'uid', 'price', 'recharge_type', 'paid', 'add_time', 'give_price', 'store_id'));
     }
 
     /**
@@ -115,12 +118,28 @@ class UserRecharge extends BaseModel
         $mark = '成功充值余额' . floatval($order['price']) . '元' . ($order['give_price'] ? ',赠送' . $order['give_price'] . '元' : '');
         $res2 = UserBill::income('用户余额充值', $order['uid'], 'now_money', 'recharge', $order['price'], $order['id'], $user['now_money'], $mark);
         $res3 = User::edit(['now_money' => bcadd($user['now_money'], $price, 2)], $order['uid'], 'uid');
-        $res = $res1 && $res2 && $res3;
+        $res = $res1 && $res2 && $res3 && self::sendRechargeAward($order);
         self::checkTrans($res);
+        if ($user['phone'])
+            OtherSMSService::send($user['phone'], $mark);
         event('RechargeSuccess', [$order]);
         return $res;
     }
 
+    public static function sendRechargeAward($order)
+    {
+        if (!$order['store_id']) return true;
+        $store = SystemStore::get($order['store_id']);
+        if (!$store) return true;
+        $ratio = $store['recharge_award_ratio'];
+        if ($ratio <= 0) return true;
+        $ratio = bcdiv($ratio, 100, 4);
+        $brokerage = bcmul($order['price'], $ratio, 2);
+        if ($brokerage <= 0) return true;
+        $res = SystemStore::where('id', $order['store_id'])->inc('brokerage_price', $brokerage)->update();
+        return $res && SystemStoreBill::expend('充值佣金', $order['store_id'], 'brokerage_price', 'recharge_award', $brokerage, $order['id'], ($store['brokerage_price'] + (float)$brokerage), '用户扫描店铺二维码充值' . $order['price'] . '元返利');
+    }
+
     /**
      * 导入佣金到余额
      * @param $uid 用户uid
@@ -162,7 +181,7 @@ class UserRecharge extends BaseModel
                 'real_name' => $user['nickname'],
                 'extract_type' => 'balance',
                 'extract_price' => $price,
-                'balance' => bcsub($user['brokerage_price'],$price,2),
+                'balance' => bcsub($user['brokerage_price'], $price, 2),
                 'add_time' => time(),
                 'status' => 1
             ];

+ 58 - 0
crmeb/services/OtherSMSService.php

@@ -0,0 +1,58 @@
+<?php
+
+namespace crmeb\services;
+
+use think\facade\Db;
+
+/**
+ * 短信服务
+ * Class SMSService
+ * @package crmeb\services
+ */
+class OtherSMSService
+{
+
+    public static function send($phone, $str)
+    {
+        $target = "http://cf.51welink.com/submitdata/Service.asmx/g_Submit";
+        $company = sys_config('site_name');
+        $content = sprintf('【' . $company . '】' . $str);
+        $post_data = "sname=dlycwl01&spwd=ycwl123456&scorpid=&sprdid=1012818&sdst=" . $phone . "&smsg=" . rawurlencode($content);
+        $gets = self::post($post_data, $target);
+        if ($gets) {
+
+            return ['status' => 200, 'msg' => '短信发送成功'];
+
+        } else {
+            return ['status' => 400, 'msg' => '发送失败'];
+        }
+    }
+
+    //第三方短信平台
+    private static function post($data, $target)
+    {
+        $url_info = parse_url($target);
+        $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
+        $httpheader .= "Host:" . $url_info['host'] . "\r\n";
+        $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n";
+        $httpheader .= "Content-Length:" . strlen($data) . "\r\n";
+        $httpheader .= "Connection:close\r\n\r\n";
+        //$httpheader .= "Connection:Keep-Alive\r\n\r\n";
+        $httpheader .= $data;
+
+        $fd = fsockopen($url_info['host'], 80);
+        fwrite($fd, $httpheader);
+        $gets = "";
+        while (!feof($fd)) {
+            $gets .= fread($fd, 128);
+        }
+        fclose($fd);
+        if ($gets != '') {
+            $start = strpos($gets, '<?xml');
+            if ($start > 0) {
+                $gets = substr($gets, $start);
+            }
+        }
+        return $gets;
+    }
+}

+ 1 - 0
route/api/route.php

@@ -47,6 +47,7 @@ Route::group(function () {
     Route::post('admin/order/refund', 'admin.StoreOrderController/refund')->name('adminOrderRefund');//订单退款
     Route::post('admin/order/back_deposit', 'admin.StoreOrderController/back_deposit')->name('adminOrderBackDeposit');//退押金
     Route::post('order/order_verific', 'admin.StoreOrderController/order_verific')->name('order');//订单核销
+    Route::get('admin/recharge', 'admin.StoreOrderController/rechargeList')->name('rechargeList');//充值列表
 
     Route::get('order/stock', 'admin.StoreOrderController/stockList')->name('stock');//商品列表
     Route::get('order/bill', 'admin.StoreOrderController/billList')->name('bill');//营收