Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

129 linhas
5.1 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 501810442
  5. * Date: 2017/8/11
  6. * Time: 9:49
  7. */
  8. namespace console\controllers;
  9. use backend\modules\api\logic\BaseBalance;
  10. use backend\modules\zzcs\models\BaseSupplier;
  11. use common\models\Msg;
  12. use yii\web\Controller;
  13. use backend\modules\zzcs\models\BaseSupplierPurchase;
  14. use backend\modules\zzcs\models\BaseUser;
  15. class BalanceController extends Controller
  16. {
  17. public $enableCsrfValidation = false;
  18. /**
  19. * Function Description:定时任务更新已付状态
  20. * Function Name: actionTimingUpdateBalanceHis
  21. *
  22. * @return array
  23. *
  24. * @author LUOCJ
  25. */
  26. public function actionTimingUpdateBalanceHis()
  27. {
  28. $user_id = 1;
  29. $data = BaseBalance::timingUpdateBalanceMain($user_id);
  30. if (!file_exists(__DIR__ . '/../log/balance')) {
  31. mkdir(__DIR__ . '/../log/balance');
  32. }
  33. 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);
  34. }
  35. /**
  36. * @Author wanglg
  37. * @Desc 通过定时任务执行该接口轮询修改渠道已付订单的订单状态
  38. */
  39. public function actionTimingUpdateChannelBalanceHis()
  40. {
  41. $user_id = 1;
  42. $data = BaseBalance::timingUpdateChannelBalanceMain($user_id);
  43. if (!file_exists(__DIR__ . '/../log/balance')) {
  44. mkdir(__DIR__ . '/../log/balance');
  45. }
  46. 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);
  47. }
  48. /**
  49. * Function Description:发送余额提醒短信
  50. * Function Name: actionSendMessage
  51. *
  52. * @author LUOCJ
  53. */
  54. public function actionSendMessage()
  55. {
  56. $content = "供应商{供应商}的预付款余额已经低于警戒值,当前为 {余额}元。请及时确认。";
  57. $models = BaseSupplier::find()->where(['and', ['=', 'CANCEL_FLAG', 0], ['=', 'SUPPLIER_TYPE', 187], ['<', 'ACCOUNT_BALANCE', 'ALERT_BALANCE']])->all();
  58. foreach ($models as $k => $model) {
  59. $phones = [];
  60. $bsp_models = BaseSupplierPurchase::findAll(['SUPPLIER_ID' => $model->ID, 'CANCEL_FLAG' => 0, 'PRODUCT_TYPE' => 25]);
  61. foreach ($bsp_models as $bsp_model) {
  62. $user_model = BaseUser::findOne(['ID' => $bsp_model->PURCHASER_NAME]);
  63. $phones[] = $user_model->PHONE_no;
  64. }
  65. if (count($phones) > 0) {
  66. $phones_str = implode(',', $phones);
  67. } else {
  68. continue;
  69. }
  70. if (strlen($phones_str) < 10) {
  71. continue;
  72. }
  73. $tp_content = $content;
  74. $tp_content = str_replace(['{供应商}', '{余额}'], [$model->SUPPLIER_NAME, $model->ALERT_BALANCE], $tp_content);
  75. $res = Msg::sendTelMsg($phones_str, $tp_content);
  76. if ($res !== 0) {
  77. if (!file_exists(__DIR__ . '/../log/balance')) {
  78. mkdir(__DIR__ . '/../log/balance');
  79. }
  80. 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);
  81. }
  82. }
  83. }
  84. /**
  85. * @Author wanglg
  86. * @Desc渠道商余额小于预警金额时给渠道商采购人发送预警短信(定时任务)
  87. */
  88. public function actionSendChannelMessage()
  89. {
  90. $content = "渠道商{渠道商}的预付款余额已经低于警戒值,当前为 {余额}元。请及时确认。";
  91. $models = BaseSupplier::find()->where(['and', ['=', 'CANCEL_FLAG', 0], ['=', 'SUPPLIER_TYPE', 301], ['<', 'ACCOUNT_BALANCE', 'ALERT_BALANCE']])->all();
  92. foreach ($models as $k => $model) {
  93. $phones = [];
  94. $bsp_models = BaseSupplierPurchase::findAll(['SUPPLIER_ID' => $model->ID, 'CANCEL_FLAG' => 0, 'PRODUCT_TYPE' => 25]);
  95. foreach ($bsp_models as $bsp_model) {
  96. $user_model = BaseUser::findOne(['ID' => $bsp_model->PURCHASER_NAME]);
  97. $phones[] = $user_model->PHONE_no;
  98. }
  99. if (count($phones) > 0) {
  100. $phones_str = implode(',', $phones);
  101. } else {
  102. continue;
  103. }
  104. if (strlen($phones_str) < 10) {
  105. continue;
  106. }
  107. $tp_content = $content;
  108. $tp_content = str_replace(['{供应商}', '{余额}'], [$model->SUPPLIER_NAME, $model->ACCOUNT_BALANCE], $tp_content);
  109. $res = Msg::sendTelMsg($phones_str, $tp_content);
  110. if ($res !== 0) {
  111. if (!file_exists(__DIR__ . '/../log/balance')) {
  112. mkdir(__DIR__ . '/../log/balance');
  113. }
  114. 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);
  115. }
  116. }
  117. }
  118. }