1, ]; $merList = D('RetailMerchant')->getSelect($mMap, 'id,name,mobile'); $Plug = new Plug(); $Arrearage = new CreditArrearageModel(); $StoreAndConfig = new CreditStoreConfigViewModel(); $AlidayuController = new AlidayuController(); foreach ($merList as $value) { $PlugData = $Plug->PlugPermissions(['merchant_id' => $value['id'], 'identification_arr' => ['credit']]); if (empty($PlugData['data']['plug']['credit'])) { continue; } else { $storeMap = [ 'merchantid' => $value['id'], 'status' => 1, 'state' => 0, 'is_credit' => 1, ]; //门店数量 $storeOfMerchant = $StoreAndConfig->getCount($storeMap); //门店Id和赊账提醒电话数组 $storeInfo = $StoreAndConfig->getSelect($storeMap, 'credit_phone,id,storetag'); //商户本月待还金额总计 $storeArrMoneyTotal = 0; //商户总待还金额统计 $storeTotalRepayMoney = 0; foreach ($storeInfo as $val) { $month_begin = mktime(0, 0, 0, date('m'), 1, date('Y')); $month_end = mktime(23, 59, 59, date('m'), date('t'), date('Y')); $monthWhere = [ 'store_id' => $val['id'], 'status' => 1, 'add_time' => ['between', [$month_begin, $month_end]], 'state' => 2, ]; // 本月赊账待还金额 $ArrearageWaitMoney = $Arrearage->getSum($monthWhere, 'money'); $monthWhere['add_time'] = ['lt', time()]; // 总待还 $ArrearageTotalWaitMoney = $Arrearage->getSum($monthWhere, 'money'); // 门店设置通知手机号 $storeArrMoneyTotal += $ArrearageWaitMoney; $storeTotalRepayMoney += $ArrearageTotalWaitMoney; if (empty($val['credit_phone'])) { continue; } else { $creditPhoneArr = json_decode($val['credit_phone'], true); $sendData = [ 'store_name' => $storeInfo['storetag'], 'month_wait_still' => $ArrearageWaitMoney, 'all_wait_still' => $ArrearageTotalWaitMoney, ]; $AlidayuController->sendCreditRemind($creditPhoneArr, $sendData, $value['id'], 2); } } $merSendData = [ 'store_count' => $storeOfMerchant, 'month_wait_still' => $storeArrMoneyTotal, 'all_wait_still' => $storeTotalRepayMoney, ]; $AlidayuController->sendCreditRemind([$merList['mobile']], $merSendData, $value['id'], 1); } } } }