multi-store/app/api/controller/IndexController.php

228 lines
7.2 KiB
PHP
Raw Normal View History

2024-05-30 21:37:55 +08:00
<?php
namespace app\api\controller;
2024-08-02 12:58:31 +08:00
use app\common\logic\StoreFinanceFlowLogic;
2024-06-13 17:49:42 +08:00
use app\admin\logic\store_product\StoreProductLogic;
2024-05-30 21:37:55 +08:00
use app\admin\validate\tools\GenerateTableValidate;
use app\admin\logic\tools\GeneratorLogic;
use app\api\logic\order\OrderLogic as OrderOrderLogic;
use app\common\logic\PayNotifyLogic;
use app\common\logic\store_order\StoreOrderLogic;
use app\common\model\Config as ModelConfig;
2024-06-13 17:49:42 +08:00
use app\common\model\store_branch_product\StoreBranchProduct;
2024-08-02 12:58:31 +08:00
use app\common\model\store_finance_flow\StoreFinanceFlow;
use app\common\model\store_order\StoreOrder;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
use app\common\service\pay\PayService;
use app\common\service\PushService;
use app\common\service\wechat\WechatTemplate;
use app\statistics\logic\OrderLogic;
use Exception;
2024-06-26 16:38:04 +08:00
use Overtrue\EasySms\EasySms;
use Overtrue\EasySms\Exceptions\NoGatewayAvailableException;
2024-06-06 09:45:43 +08:00
use support\Cache;
2024-05-30 21:37:55 +08:00
use think\facade\Db;
use Webman\Config;
use support\Log;
use Yansongda\Pay\Exception\InvalidSignException;
use Monolog\Handler\RotatingFileHandler;
use Webman\RedisQueue\Redis;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;
2024-06-14 15:53:47 +08:00
2024-05-30 21:37:55 +08:00
class IndexController extends BaseApiController
{
public $notNeedLogin = ['index', 'app_update', 'express_list', 'province', 'city', 'area', 'street', 'village', 'brigade', 'config', 'push'];
2024-05-30 21:37:55 +08:00
public function index()
2024-06-26 16:38:04 +08:00
{
return json([1]);
2024-06-26 16:38:04 +08:00
2024-08-02 12:58:31 +08:00
$financeFlow = new StoreFinanceFlow();
$order_id = 544;
$store_id = 3;
$staff_id = 3;
2024-08-02 12:58:31 +08:00
Db::startTrans();
try {
// $res = $financeFlow->where('order_id', $order_id)->update(['store_id' => $store_id, 'staff_id' => $staff_id]);
// if ($res) {
// $order['store_id'] =$store_id;
// }
$financeFlowLogic = new StoreFinanceFlowLogic();
//other_uid大于0的
$select_1 = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 1, 'status' => 0])->where('other_uid', '>', 0)->select();
foreach ($select_1 as $k => $v) {
if ($v['other_uid'] > 0) {
$financeFlowLogic->updateStatusUser($v['id'], $v['other_uid'], $v['number'], $v['order_id']);
}
2024-08-02 12:58:31 +08:00
}
$deposit = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 0, 'financial_type' => 11, 'status' => 0])->value('number') ?? 0;
$money = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 2, 'status' => 0])->value('number') ?? 0;
$financeFlowLogic->updateStatusStore($order_id, $store_id, $money, $deposit);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
d($e);
return false;
}
2024-08-02 12:58:31 +08:00
2024-06-26 16:38:04 +08:00
$all_where['paid'] = 1;
d(OrderLogic::dayPayPrice($all_where, date('Y-m-d', time())));
$uid = 9;
$a = PushService::push('wechat_mmp_' . $uid, $uid, ['type' => 'INDUSTRYMEMBERS', 'msg' => '支付超时,订单已被取消,请重新提交订单', 'data' => ['id' => 5]]);
return json($a);
2024-06-06 09:41:58 +08:00
2024-06-14 15:53:47 +08:00
try {
$a = new WechatTemplate();
$a->NewQuotationNotification(['openid' => 'ocqhF6UfFQXE-SbzbP5YVQJlQAh0', 'data1' => '阿萨', 'data2' => date('Y-m-d H:i:s'), 'data3' => '占山', 'data3' => 18982406440]);
} catch (Exception $e) {
d($e);
}
2024-06-04 16:51:26 +08:00
2024-06-14 15:53:47 +08:00
d(22);
$auth_code = $this->request->get('code');
$pay = (new PayService());
$order = [
'description' => '条码商品',
'out_trade_no' => (string)time(),
'payer' => [
'auth_code' => (string)$auth_code
],
'amount' => [
2024-06-14 15:53:47 +08:00
'total' => 1,
],
'scene_info' => [
"store_info" => [
'id' => '1'
]
],
];
2024-06-14 15:53:47 +08:00
try {
$a = $pay->wechat->pos($order);
} catch (\Exception $th) {
d($th);
}
2024-06-14 15:53:47 +08:00
d($a);
$params = ['store_id' => 2, 'pay_type' => 17];
$a = StoreOrderLogic::createOrder([1], 0, null, $params);
d($a);
return json(['msg' => create_password(123456, '11d3')]);
2024-05-30 21:37:55 +08:00
}
/**
* @notes 下载文件
*/
public function download()
{
$params = (new GenerateTableValidate())->goCheck('download');
$result = GeneratorLogic::download($params['file']);
if (false === $result) {
return $this->fail(GeneratorLogic::getError() ?: '下载失败');
}
return response()->download($result, 'webman-curd.zip');
}
/**
* @notes 获取app更新信息
*/
public function app_update()
{
$find = Db::name('app_update')->where('type', 2)->order('id', 'desc')->findOrEmpty();
return $this->success('ok', $find);
2024-05-30 21:37:55 +08:00
}
2024-06-04 16:51:26 +08:00
/**
* @notes 获取省列表
*/
public function province()
{
$list = Db::name('geo_province')->select()->toArray();
return $this->success('ok', $list);
}
/**
* @notes 获取市列表
*/
public function city()
{
2024-06-14 15:53:47 +08:00
$province_code = $this->request->get('province_code');
$list = Db::name('geo_city')->where('province_code', $province_code)->select()?->toArray();
return $this->success('ok', $list);
}
/**
* @notes 获取区列表
*/
public function area()
{
2024-06-14 15:53:47 +08:00
$city_code = $this->request->get('city_code');
$list = Db::name('geo_area')->where('city_code', $city_code)->select()?->toArray();
return $this->success('ok', $list);
}
/**
* @notes 获取街道列表
*/
public function street()
{
$area_code = $this->request->get('area_code');
$list = Db::name('geo_street')->where('area_code', $area_code)->select()?->toArray();
return $this->success('ok', $list);
}
2024-06-14 15:53:47 +08:00
/**
* @notes 获取村列表
*/
public function village()
{
$area_code = $this->request->get('street_code');
$list = Db::name('geo_village')->where('street_code', $area_code)->select()?->toArray();
return $this->success('ok', $list);
}
/**
2024-06-14 15:53:47 +08:00
* @notes 获取队列表
*/
public function brigade()
{
$list = Db::name('geo_brigade')->select()?->toArray();
return $this->success('ok', $list);
}
/**
* @notes 获取队列表
*/
public function config()
{
$store_id = getenv('STORE_ID') ?? 1;
$find = SystemStore::where('id', $store_id)->find();
$list = [
'id' => $find['id'],
'store_name' => $find['name'],
];
return $this->success('ok', $list);
2024-06-14 15:53:47 +08:00
}
public function push()
{
$name = $this->request->get('name'); //用户名
$uid = $this->request->get('uid'); //用户id
$type = $this->request->get('type', 'INDUSTRYMEMBERS'); //类型
$a = PushService::push($name, $uid, ['type' => $type, 'msg' => '支付超时,订单已被取消,请重新提交订单', 'data' => ['id' => 5]]);
return $this->success('ok', ['data' => $a]);
}
2024-05-30 21:37:55 +08:00
}