diff --git a/app/api/controller/CeshiController.php b/app/api/controller/CeshiController.php index a6c21264a..7422606e7 100644 --- a/app/api/controller/CeshiController.php +++ b/app/api/controller/CeshiController.php @@ -7,6 +7,7 @@ use app\adminapi\validate\CompanyValidate; use app\common\logic\contract\ContractLogic; use app\common\logic\finance\ShareProfit; use app\common\logic\RedisLogic; +use app\common\logic\ShopRequestLogic; use app\common\logic\task\TaskLogic; use app\common\model\Company; use app\common\model\contract\Contract; @@ -16,6 +17,9 @@ use app\common\model\task_scheduling_plan\TaskSchedulingPlan; use app\common\model\task_template\TaskTemplate; use app\job\TaskAdd; use app\job\TaskInformationJob; +use app\job\VillageTaskAdd; +use app\job\VillageTaskSettlementJob; +use think\Exception; use think\facade\Log; use app\job\TaskTenZehn; use think\facade\Db; @@ -36,6 +40,12 @@ class CeshiController extends BaseApiController 'initiate_contract', // 发起合同 'Draftingcontracts', // 发送合同 'postsms', // 发送短信 + 'addSupplyMerchant', // 添加供应商 + 'signSupplyMerchantContract', // 生成合同 + 'countRate', + 'village_task_add_test', + 'village_task_settlement_test', + 'testShopApi' ]; public function index() @@ -250,18 +260,22 @@ class CeshiController extends BaseApiController public function service_group_task_add_test() { //任务下发 + $companyId = $this->request->param('company_id'); $time = strtotime(date('Y-m-d')); // 今天的00:00:00 // 注意 cron_time - $plan_all = TaskScheduling::where('cron_time', '<', $time) + $plan_all = TaskScheduling::where('cron_time', '<', time()) ->where('status', 1) ->where('company_type', 18) + ->where('company_id', $companyId) ->with('company_info') ->select() ->toArray(); - dd($plan_all); $plan_ids = []; + dd($plan_all); foreach ($plan_all as $k => $v) { + $all = TaskTemplate::where('status', 1)->where('task_scheduling', $v['id'])->limit(30)->select()->toArray(); + $plan_ids[] = $v['id']; if ($all) { $plan_all[$k]['template'] = $all; @@ -292,12 +306,12 @@ class CeshiController extends BaseApiController $all = TaskSchedulingPlan::whereDay('end_time','today') ->withJoin(['scheduling'], 'left') ->where('scheduling.company_type', 18) + ->where('scheduling.company_id', 43) ->where('is_pay',0) ->with(['template_info']) ->select() ->toArray(); dd($all); - foreach($all as $k=>$data){ try { TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 1]); @@ -454,20 +468,32 @@ class CeshiController extends BaseApiController public function town_task_add_ceshi() { //任务下发 + $companyId = $this->request->param('company_id'); + $taskTypeIds = $this->request->param('task_type_ids'); $time = strtotime(date('Y-m-d')); // 查询系统 所有镇农科公司 未下发 的 任务安排 - $taskSchedulingList = TaskScheduling::where('cron_time', '<', $time)->where('status', 1)->where('company_type', 41)->with('company_info')->select()->toArray(); - dd($taskSchedulingList); + $taskSchedulingList = TaskScheduling::where('cron_time', '<', time()) + ->where('status', 1) + ->where('company_type', 41) + ->where('company_id', $companyId) + ->with('company_info') + ->select() + ->toArray(); + $taskSchedulingIds = []; $companyIds = []; foreach ($taskSchedulingList as $k => $taskScheduling) { $templateList = TaskTemplate::where('status', 1)->where('task_scheduling', $taskScheduling['id'])->limit(30)->select()->toArray(); + $taskSchedulingIds[] = $taskScheduling['id']; $companyIds[] = $taskScheduling['company_id']; foreach ($templateList as $template) { + if (in_array($template['type'], explode(',', $taskTypeIds))) { + TaskLogic::TownCronAdd($template); // 手动下发用 + } // queue(TownTaskAdd::class, $template); - TaskLogic::TownCronAdd($template); // 手动下发用 + } if (empty($templateList)) { @@ -477,6 +503,7 @@ class CeshiController extends BaseApiController Company::where('id', 'in', $companyIds)->inc('day_count')->update(); TaskScheduling::where('id', 'in', $taskSchedulingIds)->update(['cron_time' => time()]); Log::info('定时任务下发执行成功' . date('Y-m-d H:i:s')); + return $this->success('定时任务下发执行成功'); } /** @@ -494,10 +521,199 @@ class CeshiController extends BaseApiController ->toArray(); dd($taskSchedulingPlanList); foreach($taskSchedulingPlanList as $taskSchedulingPlan) { - if (in_array($taskSchedulingPlan['template_info']['type'], [44,45,46,47,48,49,50])) { - continue; + if ($taskSchedulingPlan['company_id'] == 30 && $taskSchedulingPlan['template_info']['type'] == 50) { + + TaskLogic::townTaskSettlement($taskSchedulingPlan); } - TaskLogic::townTaskSettlement($taskSchedulingPlan); + } + return $this->success('镇农科公司定时任务结算执行成功'); + } + + /** + * 村管理公司任务下发 + */ + public function village_task_add_test() + { + //任务下发 + $time = strtotime(date('Y-m-d')); + // 查询系统 所有镇农科公司 未下发 的 任务安排 + $taskSchedulingList = TaskScheduling::where('cron_time', '<', time()) + ->where('status', 1) + ->where('company_type', 17) + ->where('company_id', 33) + ->with('company_info') + ->select() + ->toArray(); + dd($taskSchedulingList); + $taskSchedulingIds = []; + $companyIds = []; + foreach ($taskSchedulingList as $k => $taskScheduling) { + $templateList = TaskTemplate::where('status', 1)->where('task_scheduling', $taskScheduling['id'])->limit(30)->select()->toArray(); + $taskSchedulingIds[] = $taskScheduling['id']; + $companyIds[] = $taskScheduling['company_id']; + foreach ($templateList as $template) { + + if ($template['type'] == 69) { + TaskLogic::VillageCronAdd($template); // 手动下发用 + } + + +// queue(VillageTaskAdd::class, $template); + + } + + if (empty($templateList)) { + unset($taskSchedulingList[$k]); + } + } + Company::where('id', 'in', $companyIds)->inc('day_count')->update(); + TaskScheduling::where('id', 'in', $taskSchedulingIds)->update(['cron_time' => time()]); + Log::info('村管理公司定时任务下发执行成功' . date('Y-m-d H:i:s')); + return $this->success('村管理公司定时任务下发执行成功'); + } + + /** + * 村管理公司任务结算 + */ + public function village_task_settlement_test() + { + Log::info('村管理公司定时任务结算执行-开始'.date('Y-m-d H:i:s')); + //today 今日未结算的任务计划 + $taskSchedulingPlanList = TaskSchedulingPlan::whereDay('end_time','today') + ->withJoin(['scheduling'], 'left') + ->where('scheduling.company_type', 17) + ->where('scheduling.company_id', 33) + ->where('is_pay',0) + ->with(['template_info']) + ->select() + ->toArray(); + dd($taskSchedulingPlanList); + foreach($taskSchedulingPlanList as $taskSchedulingPlan){ + if ($taskSchedulingPlan['template_info']['type'] == 69) { + TaskLogic::villageTaskSettlement($taskSchedulingPlan); + } +// queue(VillageTaskSettlementJob::class, $taskSchedulingPlan); + } + Log::info('村管理公司定时任务结算执行-结束'.date('Y-m-d H:i:s')); + return $this->success('村管理公司定时任务结算执行成功'); + } + + + public function countRate() + { + // 第一个月 + $startTime1 = strtotime(date('Y-m-d', time())); // 任务下发当天 00:00:00 + $endTime1 = strtotime("+30 day", $startTime1); // 30天后的00:00:00 + + + // 第二个月 + $startTime2 = strtotime(date('Y-m-d', $endTime1)); // 第一个月截止日 00:00:00 + $endTime2 = strtotime("+30 day", $startTime2); // 30天后的00:00:00 + dd([date('Y-m-d H:i:s', $startTime1), date('Y-m-d H:i:s', $endTime1), date('Y-m-d H:i:s', $startTime2), date('Y-m-d H:i:s', $endTime2)]); + $procureAmount = 1234; + $step = $this->request->param('step', 1); + // 商户入驻至今累计天数 + $targetProcureAmount = 10000; + // 目标采购额每阶段增幅30% + for ($i = 1; $i < $step; $i++) { + $targetProcureAmount = self::increase($targetProcureAmount); + } + dd($targetProcureAmount); + $rate = bcdiv($procureAmount, $targetProcureAmount, 2); + return $rate; + } + + private static function increase($value) + { + return bcmul($value, 1.3,2); + } + + /** + * 添加供应链商户 + */ + public function addSupplyMerchant() + { + try { + // 添加商户数据 + $params = $this->request->param(); + $data = [ + 'mer_intention_id' => 0, // 商城商户入驻申请id,签约完成后回调使用 + 'company_name' => $params['company_name']??'', + 'mer_name' => $params['mer_name']??'', // 店铺名称 + 'organization_code' => $params['organization_code']??'', + 'city' => $params['city']??'', + 'area' => $params['area']??'', + 'street' => $params['street']??'', + 'address' => $params['address']??'', + 'master_name' => $params['master_name']??'', + 'master_phone' => $params['master_phone']??'', + 'master_email' => $master_email??'', + 'type_name' => $params['type_name'] ?? '', //店铺类型 + 'category_name' => $params['category_name'] ?? '', //商户分类 + 'qualification' => !empty($params['images'])?$params['images']:json_encode([]) + ]; + $shopMerchantModel = ShopMerchant::create($data); + + $shopMerchantCertificationData = [ + 'name' => $shopMerchantModel->company_name, + 'organization_code' => $shopMerchantModel->organization_code, + 'business_license' => 'https://lihai001.oss-cn-chengdu.aliyuncs.com/def/561f8202305171526091317.png', + 'master_name' => $shopMerchantModel->master_name, + 'master_email' => $shopMerchantModel->master_email, + 'master_phone' => $shopMerchantModel->master_phone, + 'id' => $shopMerchantModel->id, + ]; + $re = app(JunziqianController::class)->ShopMerchantCertification($shopMerchantCertificationData); + + return $this->success('成功', $shopMerchantModel->toArray()); + } catch (Exception $e) { + return $this->fail($e->getMessage()); + } + + } + + // 生成合同 + public function signSupplyMerchantContract() + { + try { + $params = $this->request->param(); + // 生成合同 + $createContractData = [ + 'id' => $params['id'], + 'party_a' => $params['party_a'], + 'party_a_name' => $params['party_a_name'], + 'party_b' => $params['party_b'], + 'party_b_name' => $params['party_b_name'], + 'contract_type' => 58, // 供应链商户合同 + ]; + $model = new ShopContract(); + $model->contract_no = time(); + $model->create_time = time(); + $model->check_status = 1; + $model->update_time = time(); + $model->setAttrs($createContractData); + $res = $model->save($createContractData); + return $this->success('成功', $res->toArray()); + } catch (Exception $e) { + return $this->fail($e->getMessage()); } } + + public function testShopApi() + { + $id = $this->request->param('id'); + $templateInfo = TaskTemplate::where(['id'=>$id])->find(); + $townCompany = Company::where(['id' => $templateInfo['company_id']])->find(); + + $param['start_time'] = strtotime(date('Y-m-d', $templateInfo['cretate_time'])) + 86400; + $param['end_time'] = time(); + $param['mer_intention_id'] = 131; +// $param['goods_id'] = '17,18'; + $param['type_id'] = 10; + + + // todo 返回字段要对接 + $result = ShopRequestLogic::getGeneralMerchantProductListing($param); + dd($result); + } }