123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491 |
- <?php
- namespace app\api\controller;
- use app\models\system\SystemAttachment;
- use app\models\store\StoreCategory;
- use app\models\store\StoreCouponIssue;
- use app\models\store\StoreProduct;
- use app\models\store\StoreService;
- use app\models\store\StoreOrder;
- use app\models\store\StoreAssistanceActive;
- use app\models\system\Express;
- use app\models\system\SystemCity;
- use app\models\system\SystemStore;
- use app\models\system\SystemStoreStaff;
- use app\models\user\UserBill;
- use app\models\user\WechatUser;
- use app\models\user\UserBrokerage;
- use app\models\user\UserRecharge;
- use app\models\wechat\WechatTemplate;
- use app\Request;
- use crmeb\services\CacheService;
- use crmeb\services\MiniProgramService;
- use crmeb\services\UploadService;
- use crmeb\services\UtilService;
- use crmeb\subscribes\OrderSubscribe;
- use crmeb\repositories\PaymentRepositories;
- use crmeb\services\workerman\ChannelService;
- use crmeb\jobs\PaySuccessJob;
- use Exception;
- use Psr\SimpleCache\InvalidArgumentException;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\facade\Cache;
- use app\models\store\StorePink;
- use app\models\user\User;
- class PublicController
- {
-
- public function test()
- {
- dump(MiniProgramService::profit_sharing(
- '4200000744202011046045636579',
- 'wx160447244549420541',
- [
- [
- 'type' => 'PERSONAL_OPENID',
- 'account' => 'oSAh95RkTKmfzT_s1KaAkIuDMDP0',
- 'amount' => 2,
- 'description' => '测试分账'
- ],
- [
- 'type' => 'PERSONAL_OPENID',
- 'account' => 'oSAh95ZJfUnDWWdZ-z7wfBkUz_B0',
- 'amount' => 1,
- 'description' => '测试分账'
- ]
- ],
- 11
- ));
- }
- public function test111()
- {
- $res = StoreOrder::where('mer_id', 11)->where('transaction_id', '<>', '')->where('assistance_id', '=', '')->select();
- foreach($res as $value){
- dump(MiniProgramService::profit_sharing_finish(
- $value['transaction_id'],
- $value['order_id'],
- $value['mer_id']
- ));
- }
- }
- public function test222()
- {
- $res = UserRecharge::where('mer_id', 11)->where('transaction_id', '<>', '')->select();
- foreach($res as $value){
- dump(MiniProgramService::profit_sharing_finish(
- $value['transaction_id'],
- $value['order_id'],
- $value['mer_id']
- ));
- }
- }
- public function order_pay_success()
- {
- $orderId = 'wx160679322986954873';
- $order = StoreOrder::where('order_id', $orderId)->find();
- OrderSubscribe::onOrderPaySuccess($order);
- }
- public function profitSharingFinish(Request $request)
- {
- list($order_id) = UtilService::getMore([
- ['order_id', ''],
- ], $request, true);
- $order = StoreOrder::where('order_id', $order_id)->find();
- PaySuccessJob::profitSharingFinish($order);
- }
- public function test_profit_sharing_finish()
- {
- dump(MiniProgramService::profit_sharing_finish(
- '4200000753202011045607878421',
- 'wx160445808633819879',
- 11
- ));
- }
- public function test_recharge(Request $request)
- {
- list($order_id) = UtilService::getMore([
- ['order_id', ''],
- ], $request, true);
- UserRecharge::rechargeSuccess($order_id);
- }
- public function test_refund()
- {
- $refund_no = UserBrokerage::getNewRefundNo();
- dump(MiniProgramService::payOrderRefund(
- 'wx2020102914273410024',
- [
- 'pay_price' => 0.1,
- 'refund_price' => 0.01,
- 'refund_id' => $refund_no
- ],
- 11
- ));
- }
- public function wechat_user_recharge()
- {
- $orderNo = 'wx2020110616055410365';
- PaymentRepositories::wechatUserRechargeCard($orderNo);
- }
- public function pay_success(Request $request)
- {
- list($orderId) = UtilService::postMore([
- ['order_id', ''],
- ], $request, true);
- PaymentRepositories::wechatProduct($orderId);
- }
- public function test2($order_id)
- {
- $order = StoreOrder::where('order_id', $orderId)->find();
- if ($order->assistance_id && $res1 && !$order->refund_status) $resAssistance = StoreAssistanceActive::createAssistanceActive($order);
- }
- public function test3(Request $request)
- {
- $mer_id = 11;
- list($uni) = UtilService::postMore([
- ['uni', ''],
- ], $request, true);
- $uid = 24;
- $order = StoreOrder::getUserOrderDetail($uid, $uni, $mer_id);
- $res = User::backOrderBrokerage($order);
- return $res;
- }
- public function clearCache(Request $request)
- {
- $config_name = UtilService::postMore([
- ['name', ''],
- ], $request);
- $cacheName = "data_{$config_name['name']}";
- return CacheService::delete($cacheName);
- }
-
- public function index(Request $request)
- {
- $mer_id = $request->mer_id() ?: '';
- $banner = sys_data('routine_home_banner', 0, $mer_id) ?: [];
- $menus = sys_data('routine_home_menus', 0, $mer_id) ?: [];
- $roll = sys_data('routine_home_roll_news', 0, $mer_id) ?: [];
- $activity = sys_data('routine_home_activity', 5, $mer_id) ?: [];
- $explosive_money = sys_data('index_categy_images', 0, $mer_id) ?: [];
- $site_name = sys_config('site_name', '', $mer_id);
- $routine_index_page = sys_data('routine_index_page', 0, $mer_id);
- $info['fastInfo'] = $routine_index_page[0]['fast_info'] ?? '';
- $info['bastInfo'] = $routine_index_page[0]['bast_info'] ?? '';
- $info['firstInfo'] = $routine_index_page[0]['first_info'] ?? '';
- $info['salesInfo'] = $routine_index_page[0]['sales_info'] ?? '';
- $logoUrl = sys_config('routine_index_logo', '', $mer_id);
- if (strstr($logoUrl, 'http') === false && $logoUrl) $logoUrl = sys_config('site_url', '', $mer_id) . $logoUrl;
- $logoUrl = str_replace('\\', '/', $logoUrl);
- $fastNumber = sys_config('fast_number', 0, $mer_id);
- $bastNumber = sys_config('bast_number', 0, $mer_id);
- $firstNumber = sys_config('first_number', 0, $mer_id);
- $promotionNumber = sys_config('promotion_number', 0, $mer_id);
- $info['fastList'] = StoreCategory::byIndexList((int)$fastNumber, false, $mer_id);
- $info['bastList'] = StoreProduct::getBestProduct('id,image,store_name,cate_id,price,ot_price,IFNULL(sales,0) + IFNULL(ficti,0) as sales,unit_name', (int)$bastNumber, $request->uid(), false, 0, 0, $mer_id);
- $info['firstList'] = StoreProduct::getNewProduct('id,image,store_name,cate_id,price,unit_name,IFNULL(sales,0) + IFNULL(ficti,0) as sales', (int)$firstNumber, $request->uid(), false, 0, 0, $mer_id);
- $info['bastBanner'] = sys_data('routine_home_bast_banner', 0, $mer_id) ?? [];
- $benefit = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name', $promotionNumber, 0, 0, $mer_id);
- $lovely = sys_data('routine_home_new_banner', 0, $mer_id) ?: [];
- $likeInfo = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,ot_price,unit_name', 3, $request->uid(), 0, 0, $mer_id);
- $couponList = StoreCouponIssue::getIssueCouponList($request->uid(), 3);
- if ($request->uid()) {
- $subscribe = WechatUser::where('uid', $request->uid())->value('subscribe') ? true : false;
- } else {
- $subscribe = true;
- }
- $newGoodsBananr = sys_config('new_goods_bananr', '', $mer_id);
- $tengxun_map_key = sys_config('tengxun_map_key', '', $mer_id);
- return app('json')->successful(compact('banner', 'menus', 'roll', 'info', 'activity', 'lovely', 'benefit', 'likeInfo', 'logoUrl', 'couponList', 'site_name', 'subscribe', 'newGoodsBananr', 'tengxun_map_key', 'explosive_money'));
- }
-
- public function getStoreProduct(Request $request)
- {
- $data = UtilService::getMore([
- ['page', 1],
- ['limit', 4],
- ], $request);
- $res = SystemStore::getStoreProduct($data['page'], $data['limit'], $request->mer_id());
- return app('json')->successful($res);
- }
-
- public function share(Request $request)
- {
- $mer_id = $request->mer_id();
- $data['img'] = sys_config('wechat_share_img', '', $mer_id);
- if (strstr($data['img'], 'http') === false) $data['img'] = sys_config('site_url', '', $mer_id) . $data['img'];
- $data['img'] = str_replace('\\', '/', $data['img']);
- $data['title'] = sys_config('wechat_share_title', '', $mer_id);
- $data['synopsis'] = sys_config('wechat_share_synopsis', '', $mer_id);
- return app('json')->successful(compact('data'));
- }
-
- public function menu_user(Request $request)
- {
- $menusInfo = sys_data('routine_my_menus', 0, $request->mer_id()) ?? [];
- $user = $request->user();
- $vipOpen = sys_config('vip_open', '', $request->mer_id());
- $vipOpen = is_string($vipOpen) ? (int)$vipOpen : $vipOpen;
- foreach ($menusInfo as $key => &$value) {
- $value['pic'] = set_file_url($value['pic']);
- if ($value['id'] == 137 && !(intval(sys_config('store_brokerage_statu', '', $request->mer_id())) == 2 || $user->is_promoter == 1))
- unset($menusInfo[$key]);
- if ($value['id'] == 174 && !StoreService::orderServiceStatus($user->uid))
- unset($menusInfo[$key]);
- if (((!StoreService::orderServiceStatus($user->uid)) && (!SystemStoreStaff::verifyStatus($user->uid))) && $value['url'] === '/pages/admin/order_cancellation/index')
- unset($menusInfo[$key]);
- if ((!StoreService::orderServiceStatus($user->uid)) && $value['url'] === '/pages/admin/order/index')
- unset($menusInfo[$key]);
- if ($value['url'] == '/pages/users/user_vip/index' && !$vipOpen)
- unset($menusInfo[$key]);
- }
- $bannerInfo = sys_data('routine_my_banner', 0, $request->mer_id()) ?? [];
- return app('json')->successful(['routine_my_menus' => $menusInfo, 'routine_my_banner' => $bannerInfo]);
- }
-
- public function search(Request $request)
- {
- $routineHotSearch = sys_data('routine_hot_search', 0, $request->mer_id()) ?? [];
- $searchKeyword = [];
- if (count($routineHotSearch)) {
- foreach ($routineHotSearch as $key => &$item) {
- array_push($searchKeyword, $item['title']);
- }
- }
- return app('json')->successful($searchKeyword);
- }
-
- public function upload_image(Request $request)
- {
- $data = UtilService::postMore([
- ['filename', 'file'],
- ], $request);
- if (!$data['filename']) return app('json')->fail('参数有误');
- if (Cache::has('start_uploads_' . $request->uid()) && Cache::get('start_uploads_' . $request->uid()) >= 100) return app('json')->fail('非法操作');
- $upload = UploadService::init(null, $request->mer_id());
- $info = $upload->to('store/comment')->validate()->move($data['filename']);
- if ($info === false) {
- return app('json')->fail($upload->getError());
- }
- $res = $upload->getUploadInfo();
- SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 1, (int)sys_config('upload_type', 1), $res['time'], 2);
- if (Cache::has('start_uploads_' . $request->uid()))
- $start_uploads = (int)Cache::get('start_uploads_' . $request->uid());
- else
- $start_uploads = 0;
- $start_uploads++;
- Cache::set('start_uploads_' . $request->uid(), $start_uploads, 86400);
- $res['dir'] = path_to_url($res['dir']);
- if (strpos($res['dir'], 'http') === false) $res['dir'] = $request->domain() . $res['dir'];
- return app('json')->successful('图片上传成功!', ['name' => $res['name'], 'url' => $res['dir']]);
- }
-
- public function logistics()
- {
- $expressList = Express::lst();
- if (!$expressList) return app('json')->successful([]);
- return app('json')->successful($expressList->hidden(['code', 'id', 'sort', 'is_show'])->toArray());
- }
-
- public function sms_pay_notify(Request $request)
- {
- list($order_id, $price, $status, $num, $pay_time, $attach) = UtilService::postMore([
- ['order_id', ''],
- ['price', 0.00],
- ['status', 400],
- ['num', 0],
- ['pay_time', time()],
- ['attach', 0],
- ], $request, true);
- if ($status == 200) {
- try {
- ChannelService::instance()->send('PAY_SMS_SUCCESS', ['price' => $price, 'number' => $num], [$attach]);
- } catch (\Throwable $e) {
- }
- return app('json')->successful();
- }
- return app('json')->fail();
- }
-
- public function user_share(Request $request)
- {
- return app('json')->successful(UserBill::setUserShare($request->uid(), 300, $request->mer_id()));
- }
-
- public function get_image_base64(Request $request)
- {
- list($imageUrl, $codeUrl) = UtilService::postMore([
- ['image', ''],
- ['code', ''],
- ], $request, true);
- try {
- $codeTmp = $code = $codeUrl ? image_to_base64($codeUrl) : false;
- if (!$codeTmp) {
- $putCodeUrl = put_image($codeUrl);
- $code = $putCodeUrl ? image_to_base64($_SERVER['HTTP_HOST'] . '/' . $putCodeUrl) : false;
- $code ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putCodeUrl);
- }
- $imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : false;
- if (!$imageTmp) {
- $putImageUrl = put_image($imageUrl);
- $image = $putImageUrl ? image_to_base64($_SERVER['HTTP_HOST'] . '/' . $putImageUrl) : false;
- $image ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putImageUrl);
- }
- return app('json')->successful(compact('code', 'image'));
- } catch (Exception $e) {
- return app('json')->fail($e->getMessage());
- }
- }
-
- public function store_list(Request $request)
- {
- list($latitude, $longitude, $page, $limit, $product_id) = UtilService::getMore([
- ['latitude', ''],
- ['longitude', ''],
- [['page', 'd'], 1],
- [['limit', 'd'], 10],
- ['product_id', '']
- ], $request, true);
- $list = SystemStore::lst($latitude, $longitude, $page, $limit, '', 0, $request->mer_id(), $product_id);
- if (!$list) $list = [];
- $data['list'] = $list;
- $data['tengxun_map_key'] = sys_config('tengxun_map_key', '', $request->mer_id());
- return app('json')->successful($data);
- }
-
- public function city_list(Request $request)
- {
- $list = CacheService::get('CITY_LIST', function () {
- $list = SystemCity::with('children')->field(['city_id', 'name', 'id', 'parent_id'])->where('parent_id', 0)->order('id asc')->select()->toArray();
- $data = [];
- foreach ($list as &$item) {
- $value = ['v' => $item['city_id'], 'n' => $item['name']];
- if ($item['children']) {
- foreach ($item['children'] as $key => &$child) {
- $value['c'][$key] = ['v' => $child['city_id'], 'n' => $child['name']];
- unset($child['id'], $child['area_code'], $child['merger_name'], $child['is_show'], $child['level'], $child['lng'], $child['lat'], $child['lat']);
- if (SystemCity::where('parent_id', $child['city_id'])->count()) {
- $child['children'] = SystemCity::where('parent_id', $child['city_id'])->field(['city_id', 'name', 'id', 'parent_id'])->select()->toArray();
- foreach ($child['children'] as $kk => $vv) {
- $value['c'][$key]['c'][$kk] = ['v' => $vv['city_id'], 'n' => $vv['name']];
- }
- }
- }
- }
- $data[] = $value;
- }
- return $data;
- }, 0);
- return app('json')->successful($list);
- }
-
- public function pink(Request $request)
- {
- $data['pink_count'] = StorePink::merSet($request->mer_id())->where(['status' => 2, 'is_refund' => 0])->count();
- $data['avatars'] = User::whereIn('uid', function ($query) {
- $query->name('store_pink')->where(['status' => 2, 'is_refund' => 0])->field(['uid'])->select();
- })->limit(3)->order('uid desc')->column('avatar');
- return app('json')->successful($data);
- }
- }
|