| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- namespace addons\Community\backend\controllers;
- use addons\Community\common\enums\CommunityEnum;
- use addons\Community\common\service\SettingService;
- use addons\Community\common\listeners\OrderPaidListener;
- use common\enums\OrderStatusEnum;
- use Yii;
- use yii\helpers\Json;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Community\backend\controllers
- */
- class DefaultController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- if (Yii::$app->request->isAjax) {
- $service = new SettingService();
- if (Yii::$app->request->isGet) {
- $ret = $service->get($this->mall_id);
- if (empty($ret)) {
- $ret = [
- 'position_range' => 1,
- 'can_receive_day' => 1,
- 'pick_up_time_range_type' => 0,
- 'settlement_type' => 1,
- 'calculate_type' => 0,
- 'head_commission_type' => 0,
- 'commission' => '',
- 'pick_up_time_range_custom' => [],
- 'pick_up_time_range_custom_at' => [],
- 'area' => [],
- 'not_area' => [],
- 'apply_pic' => '',
- 'protocol_content' => '',
- 'protocol_title' => '',
- 'is_enable_reward' => 0,
- 'is_enable' => 0,
- 'sms' => [],
- 'is_enable_write_off' => 0,
- 'is_platform_distribution' => 0,
- 'is_force_free_shipping' => 0,
- ];
- } else {
- if (!empty($ret['area']))
- {
- $ret['area'] = Json::decode($ret['area']);
- } else {
- $ret['area'] = [];
- }
- if (!empty($ret['not_area']) && !empty($ret['area'])) {
- // 因为区域如果只选择第三级。但是area中因为需求要存一、二级ID。 所以返回前段时要去掉一、二级ID。
- $ret['not_area'] = Json::decode($ret['not_area']);
- $ret['area'] = array_filter($ret['area'], function ($item) use ($ret) {
- return !in_array($item, $ret['not_area']);
- });
- $ret['all_area'] = array_values($ret['not_area']);
- unset($ret['not_area']);
- } else {
- $ret['not_area'] = [];
- }
- if (!empty($ret['sms'])) {
- $ret['sms'] = Json::decode($ret['sms']);
- } else {
- $ret['sms'] = [];
- }
- if (!empty($ret['pick_up_time_range_custom'])) {
- $ret['pick_up_time_range_custom'] = Json::decode($ret['pick_up_time_range_custom']);
- $ret['pick_up_time_range_custom_at'] = Json::decode($ret['pick_up_time_range_custom_at']);
- foreach ($ret['pick_up_time_range_custom_at'] as &$item) {
- $item = sprintf("%s %s", date('Y-m-d'), $item);
- }
- }
- }
- return $this->success('获取成功', $ret);
- } else if(Yii::$app->request->isPost) {
- $data = Yii::$app->request->post('body');
- $data = Json::decode($data);
- $valid = Yii::$app->services->validate->validate($data, [
- [['position_range', 'can_receive_day', 'pick_up_time_range_type',
- 'settlement_type', 'calculate_type', 'head_commission_type', 'commission'], 'number'],
- [['pick_up_time_range_custom', 'pick_up_time_range_custom_at', 'area', 'protocol_title', 'sms', 'not_area'], 'safe'],
- [['apply_pic', 'protocol_content'], 'string'],
- [['is_enable_reward', 'is_enable', 'is_enable_write_off', 'is_force_free_shipping', 'is_platform_distribution'], 'integer']
- ]);
- if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $data['area'] = !empty($data['area']) ? Json::encode(array_unique($data['area'])) : '';
- $data['not_area'] = !empty($data['not_area']) ? Json::encode(array_unique($data['not_area'])) : '';
- $data['sms'] = !empty($data['sms']) ? Json::encode($data['sms']) : Json::encode([]);
- if (!empty($data['pick_up_time_range_custom_at'])) {
- foreach ($data['pick_up_time_range_custom_at'] as &$datum) {
- $d = strtotime($datum);
- $datum = date('H:i:s', $d);
- }
- }
- $data['pick_up_time_range_custom_at'] = !empty($data['pick_up_time_range_custom_at']) ?
- Json::encode($data['pick_up_time_range_custom_at']) : Json::encode([]);
- $data['pick_up_time_range_custom'] = !empty($data['pick_up_time_range_custom']) ?
- Json::encode($data['pick_up_time_range_custom']) : Json::encode([]);
- return $service->save($this->mall_id, $data) ? $this->success() : $this->error();
- }
- }
- return $this->render('index',[]);
- }
- public function actionSmsKeys()
- {
- // 订单
- // 团长
- // 买家
- return $this->success('获取成功', CommunityEnum::SMS_KEYS);
- }
- public function actionTest()
- {
- $data = [
- 'id' => 42670,
- ];
- $order_paid_listener = new OrderPaidListener();
- $res = $order_paid_listener->exec($data);
- print_r($res);exit;
- }
- }
|