|
- <?php
- /**
- * Created by PhpStorm.
- * User: 501810442
- * Date: 2017/8/11
- * Time: 9:49
- */
-
- namespace console\controllers;
-
- use backend\modules\api\logic\BaseBalance;
- use backend\modules\zzcs\models\BaseSupplier;
- use common\models\Msg;
- use yii\web\Controller;
- use backend\modules\zzcs\models\BaseSupplierPurchase;
- use backend\modules\zzcs\models\BaseUser;
-
- class BalanceController extends Controller
- {
- public $enableCsrfValidation = false;
-
- /**
- * Function Description:定时任务更新已付状态
- * Function Name: actionTimingUpdateBalanceHis
- *
- * @return array
- *
- * @author LUOCJ
- */
- public function actionTimingUpdateBalanceHis()
- {
- $user_id = 1;
- $data = BaseBalance::timingUpdateBalanceMain($user_id);
- if (!file_exists(__DIR__ . '/../log/balance')) {
- mkdir(__DIR__ . '/../log/balance');
- }
- file_put_contents(__DIR__ . '/../log/balance/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '刷新订单数据:' . json_encode($data) . PHP_EOL, FILE_APPEND);
-
- }
-
- /**
- * @Author wanglg
- * @Desc 通过定时任务执行该接口轮询修改渠道已付订单的订单状态
- */
- public function actionTimingUpdateChannelBalanceHis()
- {
- $user_id = 1;
- $data = BaseBalance::timingUpdateChannelBalanceMain($user_id);
- if (!file_exists(__DIR__ . '/../log/balance')) {
- mkdir(__DIR__ . '/../log/balance');
- }
- file_put_contents(__DIR__ . '/../log/balance/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '刷新订单数据:' . json_encode($data) . PHP_EOL, FILE_APPEND);
- }
-
-
- /**
- * Function Description:发送余额提醒短信
- * Function Name: actionSendMessage
- *
- * @author LUOCJ
- */
- public function actionSendMessage()
- {
- $content = "供应商{供应商}的预付款余额已经低于警戒值,当前为 {余额}元。请及时确认。";
- $models = BaseSupplier::find()->where(['and', ['=', 'CANCEL_FLAG', 0], ['=', 'SUPPLIER_TYPE', 187], ['<', 'ACCOUNT_BALANCE', 'ALERT_BALANCE']])->all();
- foreach ($models as $k => $model) {
- $phones = [];
- $bsp_models = BaseSupplierPurchase::findAll(['SUPPLIER_ID' => $model->ID, 'CANCEL_FLAG' => 0, 'PRODUCT_TYPE' => 25]);
- foreach ($bsp_models as $bsp_model) {
- $user_model = BaseUser::findOne(['ID' => $bsp_model->PURCHASER_NAME]);
- $phones[] = $user_model->PHONE_no;
- }
- if (count($phones) > 0) {
- $phones_str = implode(',', $phones);
- } else {
- continue;
- }
- if (strlen($phones_str) < 10) {
- continue;
- }
- $tp_content = $content;
- $tp_content = str_replace(['{供应商}', '{余额}'], [$model->SUPPLIER_NAME, $model->ALERT_BALANCE], $tp_content);
- $res = Msg::sendTelMsg($phones_str, $tp_content);
- if ($res !== 0) {
- if (!file_exists(__DIR__ . '/../log/balance')) {
- mkdir(__DIR__ . '/../log/balance');
- }
- file_put_contents(__DIR__ . '/../log/balance/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '供应商警戒值 短信发送失败 ' . $model->SUPPLIER_NAME . ' ' . $model->ALERT_BALANCE . PHP_EOL, FILE_APPEND);
-
- }
- }
- }
-
- /**
- * @Author wanglg
- * @Desc渠道商余额小于预警金额时给渠道商采购人发送预警短信(定时任务)
- */
- public function actionSendChannelMessage()
- {
- $content = "渠道商{渠道商}的预付款余额已经低于警戒值,当前为 {余额}元。请及时确认。";
- $models = BaseSupplier::find()->where(['and', ['=', 'CANCEL_FLAG', 0], ['=', 'SUPPLIER_TYPE', 301], ['<', 'ACCOUNT_BALANCE', 'ALERT_BALANCE']])->all();
- foreach ($models as $k => $model) {
- $phones = [];
- $bsp_models = BaseSupplierPurchase::findAll(['SUPPLIER_ID' => $model->ID, 'CANCEL_FLAG' => 0, 'PRODUCT_TYPE' => 25]);
- foreach ($bsp_models as $bsp_model) {
- $user_model = BaseUser::findOne(['ID' => $bsp_model->PURCHASER_NAME]);
- $phones[] = $user_model->PHONE_no;
- }
- if (count($phones) > 0) {
- $phones_str = implode(',', $phones);
- } else {
- continue;
- }
- if (strlen($phones_str) < 10) {
- continue;
- }
- $tp_content = $content;
- $tp_content = str_replace(['{供应商}', '{余额}'], [$model->SUPPLIER_NAME, $model->ACCOUNT_BALANCE], $tp_content);
- $res = Msg::sendTelMsg($phones_str, $tp_content);
- if ($res !== 0) {
- if (!file_exists(__DIR__ . '/../log/balance')) {
- mkdir(__DIR__ . '/../log/balance');
- }
- file_put_contents(__DIR__ . '/../log/balance/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '渠道商警戒值 短信发送失败 ' . $model->SUPPLIER_NAME . ' ' . $model->ACCOUNT_BALANCE . PHP_EOL, FILE_APPEND);
-
- }
- }
- }
- }
|