diff --git a/app/admin/controller/store_finance_flow/StoreFinanceFlowController.php b/app/admin/controller/store_finance_flow/StoreFinanceFlowController.php index a5bae6f02..a63bf0025 100644 --- a/app/admin/controller/store_finance_flow/StoreFinanceFlowController.php +++ b/app/admin/controller/store_finance_flow/StoreFinanceFlowController.php @@ -4,7 +4,10 @@ namespace app\admin\controller\store_finance_flow; use app\admin\controller\BaseAdminController; +use app\admin\lists\store_finance_flow\StoreFinanceFlowDayLists; use app\admin\lists\store_finance_flow\StoreFinanceFlowLists; +use app\admin\lists\store_finance_flow\StoreFinanceFlowMonthLists; +use app\admin\lists\store_finance_flow\StoreFinanceFlowWeekLists; use app\admin\logic\store_finance_flow\StoreFinanceFlowLogic; use app\admin\validate\store_finance_flow\StoreFinanceFlowValidate; @@ -28,6 +31,36 @@ class StoreFinanceFlowController extends BaseAdminController { return $this->dataLists(new StoreFinanceFlowLists()); } + /** + * @notes 获取日账单列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 16:56 + */ + public function day_bill_lists() + { + return $this->dataLists(new StoreFinanceFlowDayLists()); + } + /** + * @notes 获取周账单列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 16:56 + */ + public function week_bill_lists() + { + return $this->dataLists(new StoreFinanceFlowWeekLists()); + } + /** + * @notes 获取月账单列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 16:56 + */ + public function month_bill_lists() + { + return $this->dataLists(new StoreFinanceFlowMonthLists()); + } diff --git a/app/admin/controller/system_store/SystemStoreStatisticsController.php b/app/admin/controller/system_store/SystemStoreStatisticsController.php index 3f8d79e99..8f639f64e 100644 --- a/app/admin/controller/system_store/SystemStoreStatisticsController.php +++ b/app/admin/controller/system_store/SystemStoreStatisticsController.php @@ -261,7 +261,7 @@ class SystemStoreStatisticsController extends BaseAdminController [ "id"=> 46, "name"=> "王多鱼的商超", - "image"=> "https=>//multi-store.crmeb.net/uploads/attach/2024/05/20240527/f9b8b3c3cd5f1113bd7d374dc55d320a.jpg", + "image"=> "https:multi-store.crmeb.net/uploads/attach/2024/05/20240527/f9b8b3c3cd5f1113bd7d374dc55d320a.jpg", "store_price"=> 797.88, "store_product_count"=> 18, "store_order_price"=> 1275.16, @@ -270,7 +270,7 @@ class SystemStoreStatisticsController extends BaseAdminController [ "id"=> 43, "name"=> "这是直营店", - "image"=> "https=>//multi-store.crmeb.net/uploads/attach/2024/05/20240524/9066528e73e2db60d31a704d321ba4a5.jpeg", + "image"=> "https:multi-store.crmeb.net/uploads/attach/2024/05/20240524/9066528e73e2db60d31a704d321ba4a5.jpeg", "store_price"=> 203.11, "store_product_count"=> 10, "store_order_price"=> 579.01, diff --git a/app/admin/lists/store_finance_flow/StoreFinanceFlowDayLists.php b/app/admin/lists/store_finance_flow/StoreFinanceFlowDayLists.php new file mode 100644 index 000000000..c5aadb565 --- /dev/null +++ b/app/admin/lists/store_finance_flow/StoreFinanceFlowDayLists.php @@ -0,0 +1,75 @@ + ['store_id', 'uid', 'staff_id'], + 'between_time'=>'create_time' + ]; + } + + + /** + * @notes 获取门店日账单列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 16:56 + */ + public function lists(): array + { + return StoreFinanceFlow::where($this->searchWhere) + ->field(' + FROM_UNIXTIME(create_time, "%Y-%m-%d") as date, + SUM(CASE WHEN financial_pm = 1 THEN number ELSE 0 END) as income, + SUM(CASE WHEN financial_pm = 0 THEN number ELSE 0 END) as expenditure + ') + ->limit($this->limitOffset, $this->limitLength) + ->group('date') + ->order('date', 'desc') + ->select()->each(function ($item) { + $item['name']='日账单'; + $item['enter']=bcdiv($item['income'],$item['expenditure'],2); + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取门店日账单数量 + * @return int + * @author admin + * @date 2024/05/31 16:56 + */ + public function count(): int + { + return StoreFinanceFlow::where($this->searchWhere)->group('create_time') + ->count(); + } +} diff --git a/app/admin/lists/store_finance_flow/StoreFinanceFlowMonthLists.php b/app/admin/lists/store_finance_flow/StoreFinanceFlowMonthLists.php new file mode 100644 index 000000000..d35ab1269 --- /dev/null +++ b/app/admin/lists/store_finance_flow/StoreFinanceFlowMonthLists.php @@ -0,0 +1,75 @@ + ['store_id', 'uid', 'staff_id'], + 'between_time' => 'create_time' + ]; + } + + + /** + * @notes 获取门店月账单列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 16:56 + */ + public function lists(): array + { + return StoreFinanceFlow::where($this->searchWhere) + ->field(' + CONCAT(YEAR(FROM_UNIXTIME(create_time, "%Y-%m-%d")), "年", MONTH(FROM_UNIXTIME(create_time, "%Y-%m-%d")), "月") as date, + SUM(CASE WHEN financial_pm = 1 THEN number ELSE 0 END) as income, + SUM(CASE WHEN financial_pm = 0 THEN number ELSE 0 END) as expenditure + ') + ->limit($this->limitOffset, $this->limitLength) + ->group('date') + ->order('date', 'desc') + ->select()->each(function ($item) { + $item['name']='月账单'; + $item['enter']=bcdiv($item['income'],$item['expenditure'],2); + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取门店月账单数量 + * @return int + * @author admin + * @date 2024/05/31 16:56 + */ + public function count(): int + { + return StoreFinanceFlow::where($this->searchWhere)->group('create_time') + ->count(); + } +} diff --git a/app/admin/lists/store_finance_flow/StoreFinanceFlowWeekLists.php b/app/admin/lists/store_finance_flow/StoreFinanceFlowWeekLists.php new file mode 100644 index 000000000..33cf129f7 --- /dev/null +++ b/app/admin/lists/store_finance_flow/StoreFinanceFlowWeekLists.php @@ -0,0 +1,75 @@ + ['store_id', 'uid', 'staff_id'], + 'between_time' => 'create_time' + ]; + } + + + /** + * @notes 获取门店周账单列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 16:56 + */ + public function lists(): array + { + return StoreFinanceFlow::where($this->searchWhere) + ->field(' + CONCAT("第", YEARweek(FROM_UNIXTIME(create_time, "%Y-%m-%d")), "周(", MONTH(FROM_UNIXTIME(create_time, "%Y-%m-%d")), "月)") as date, + SUM(CASE WHEN financial_pm = 1 THEN number ELSE 0 END) as income, + SUM(CASE WHEN financial_pm = 0 THEN number ELSE 0 END) as expenditure + ') + ->limit($this->limitOffset, $this->limitLength) + ->group('date') + ->order('date', 'desc') + ->select()->each(function ($item) { + $item['name']='周账单'; + $item['enter']=bcdiv($item['income'],$item['expenditure'],2); + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取门店周账单数量 + * @return int + * @author admin + * @date 2024/05/31 16:56 + */ + public function count(): int + { + return StoreFinanceFlow::where($this->searchWhere)->group('create_time') + ->count(); + } +} diff --git a/app/admin/lists/system_store/SystemStoreLists.php b/app/admin/lists/system_store/SystemStoreLists.php index 791210a99..40b3804ea 100644 --- a/app/admin/lists/system_store/SystemStoreLists.php +++ b/app/admin/lists/system_store/SystemStoreLists.php @@ -6,7 +6,7 @@ namespace app\admin\lists\system_store; use app\admin\lists\BaseAdminDataLists; use app\common\model\system_store\SystemStore; use app\common\lists\ListsSearchInterface; - +use app\common\model\system_store\SystemStoreStaff; /** * 门店列表列表 @@ -47,7 +47,9 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac ->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show','day_start','day_end']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() + ->select()->each(function ($item){ + $item['staff_name'] =SystemStoreStaff::where('store_id',$item['id'])->where('is_admin',1)->value('staff_name'); + }) ->toArray(); } diff --git a/app/admin/lists/user_recharge/UserRechargeLists.php b/app/admin/lists/user_recharge/UserRechargeLists.php index 6a64019b7..6a9101e65 100644 --- a/app/admin/lists/user_recharge/UserRechargeLists.php +++ b/app/admin/lists/user_recharge/UserRechargeLists.php @@ -6,7 +6,7 @@ namespace app\admin\lists\user_recharge; use app\admin\lists\BaseAdminDataLists; use app\common\model\user_recharge\UserRecharge; use app\common\lists\ListsSearchInterface; - +use app\common\model\user\User; /** * 充值记录列表 @@ -27,6 +27,7 @@ class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterfa { return [ '=' => ['paid', 'pay_time'], + 'between_time'=>'create_time' ]; } @@ -46,7 +47,20 @@ class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterfa ->field(['id', 'uid', 'order_id', 'price', 'recharge_type', 'paid', 'pay_time']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() + ->select()->each(function ($item) { + $item['nickname']=User::where('id',$item['uid'])->value('nickname'); + if($item['pay_time']>0){ + $item['pay_time']=date('Y-m-d H:i:s',$item['pay_time']); + }else{ + $item['pay_time']=''; + } + if($item['paid']==1){ + $item['paid_name']='已充值'; + }else{ + $item['paid_name']='未充值'; + } + return $item; + }) ->toArray(); } diff --git a/app/admin/logic/system_store/SystemStoreLogic.php b/app/admin/logic/system_store/SystemStoreLogic.php index c07cc136f..f33dc41d7 100644 --- a/app/admin/logic/system_store/SystemStoreLogic.php +++ b/app/admin/logic/system_store/SystemStoreLogic.php @@ -52,7 +52,7 @@ class SystemStoreLogic extends BaseLogic 'account' => $params['phone'], 'pwd' => $password, 'avatar' => $params['image'], - 'staff_name' => $params['name'], + 'staff_name' => $params['staff_name'], 'phone' => $params['phone'], 'is_admin' => 1, 'status' => 1, @@ -95,17 +95,24 @@ class SystemStoreLogic extends BaseLogic 'area' => $params['area_code'], 'street' => $params['street_code'], ]); - if($params['password']!=''){ + $res=SystemStoreStaff::where('store_id', $params['id'])->where('is_admin', 1)->where('account', $params['phone'])->find(); + if($params['password']!=''&&$res){ $passwordSalt = Config::get('project.unique_identification'); $password = create_password($params['password'], $passwordSalt); $taff = [ 'pwd' => $password, 'avatar' => $params['image'], - 'staff_name' => $params['name'], + 'staff_name' => $params['staff_name'], ]; - SystemStoreStaff::where('store_id', $params['id'])->where('is_admin', 1)->where('account', $params['phone'])->update($taff); + SystemStoreStaff::where('id', $res['id'])->update($taff); + } + if($params['staff_name']!=''&&$res){ + $taff = [ + 'avatar' => $params['image'], + 'staff_name' => $params['staff_name'], + ]; + SystemStoreStaff::where('id', $res['id'])->update($taff); } - Db::commit(); return true; } catch (\Exception $e) { @@ -138,6 +145,10 @@ class SystemStoreLogic extends BaseLogic */ public static function detail($params): array { - return SystemStore::findOrEmpty($params['id'])->toArray(); + $data=SystemStore::findOrEmpty($params['id'])->toArray(); + if($data){ + $data['staff_name']=SystemStoreStaff::where('store_id', $params['id'])->where('is_admin', 1)->value('staff_name'); + } + return $data; } } diff --git a/app/api/controller/PayController.php b/app/api/controller/PayController.php index ec8863c73..afcc79610 100644 --- a/app/api/controller/PayController.php +++ b/app/api/controller/PayController.php @@ -28,12 +28,8 @@ class PayController extends BaseApiController { $app = new PayService(1); $result = $app->wechat->callback(Request()->post()); - Cache::set('log'.time(),json_encode($result)); - Cache::set('logE'.time(),$result->event_type); - Cache::set('logE1'.time(),$result['event_type']??''); if ($result && $result->event_type == 'TRANSACTION.SUCCESS') { $ciphertext = $result->resource['ciphertext']; - Cache::set('logc'.time(),json_encode($result->resource['ciphertext'],true)); if ($ciphertext['trade_state'] === 'SUCCESS') { $attach = $ciphertext['attach']; switch ($attach) { diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index ef4f7a801..4073951c4 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -243,13 +243,23 @@ class OrderController extends BaseApiController { $userId = $this->request->userId; $where = ['uid' => $userId, 'paid' => 0]; - $no_pay = StoreOrder::where($where)->count(); + $no_pay = StoreOrder::where($where)->count();//待付款 + $where['paid'] = 1; - $where['status'] = 0; - $waiting = StoreOrder::where($where)->count(); $where['status'] = 1; - $receiving = StoreOrder::where($where)->count(); - return $this->success('ok', ['no_pay' => $no_pay, 'waiting' => $waiting, 'receiving' => $receiving]); + $waiting = StoreOrder::where($where)->count();//待核销 + + $where['status'] = 2; + $receiving = StoreOrder::where($where)->count();//已核销 + + $where['status'] = -1; + $applyRefund= StoreOrder::where($where)->count();//申请退款 + + $where['status'] = 4; + $refund= StoreOrder::where($where)->count();//已退款 + + $all = StoreOrder::where(['uid' => $userId])->count();//全部 + return $this->success('ok', ['no_pay' => $no_pay, 'waiting' => $waiting, 'receiving' => $receiving,'all'=>$all,'applyRefund'=>$applyRefund,'refund'=>$refund]); } #[ diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index dbfc1e11d..c46678654 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -9,6 +9,8 @@ use app\common\enum\YesNoEnum; use app\common\logic\BaseLogic; use app\common\logic\CapitalFlowLogic; use app\common\logic\StoreFinanceFlowLogic; +use app\common\model\dict\DictData; +use app\common\model\dict\DictType; use app\common\model\order\Cart; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_order\StoreOrder; @@ -76,10 +78,13 @@ class OrderLogic extends BaseLogic } //TODO 收单打9.9折 会员按照比例打折 等级按照充值去升级 $pay_price = self::$total; - $check = StoreOrder::where('uid',\request()->userId)->count(); +// $check = StoreOrder::where('uid',\request()->userId)->count();//首单逻辑 + $check = DictType::where('type','activities')->find(); $vipPrice = 0; - if(empty($check)){ - $discountRate = '0.99'; + if(isset($check) && $check['status'] == 1){ +// $discountRate = '0.99';//首单逻辑 + $discountRate = $check['remark']; + $discountRate = bcdiv($discountRate, '100', 2); $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); }else{ $userVip = User::where('id',\request()->userId)->value('user_ship'); @@ -103,6 +108,7 @@ class OrderLogic extends BaseLogic default: $discountRate = 1; } + $discountRate = bcdiv($discountRate, '100', 2); $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); } } diff --git a/app/api/logic/user/UserLogic.php b/app/api/logic/user/UserLogic.php index d3dbc1c08..5e6f8e75c 100644 --- a/app/api/logic/user/UserLogic.php +++ b/app/api/logic/user/UserLogic.php @@ -65,7 +65,7 @@ class UserLogic extends BaseLogic public static function info($uid) { $data = User::with(['userShip'])->where('id',$uid) - ->field('avatar,real_name,nickname,account,mobile,sex,login_ip,user_money,total_recharge_amount,user_ship') + ->field('avatar,real_name,nickname,account,mobile,sex,login_ip,now_money,total_recharge_amount,user_ship') ->find(); //判断是不是员工 if($data){ diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 07d2ffc8c..dabcb4da6 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -130,7 +130,7 @@ class PayNotifyLogic extends BaseLogic return true; } bcscale(2); - $user->user_money = bcadd($user->user_money, $price, 2); + $user->now_money = bcadd($user->now_money, $price, 2); $user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2); $user->save(); //用户的财务add