public function searchOffice($params, $office_id) { $query = MOfficeScoreEvent::find()->where(["office_id" => $office_id])->where(['>', "cat", 100]); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'office_id' => $this->office_id, 'cat' => $this->cat, 'create_time' => $this->create_time, 'score' => $this->score, 'status' => $this->status]); $query->andFilterWhere(['like', 'gh_id', $this->gh_id])->andFilterWhere(['like', 'openid', $this->openid])->andFilterWhere(['like', 'memo', $this->memo])->andFilterWhere(['like', 'code', $this->code]); return $dataProvider; }
<?php $office = MOffice::findOne(["office_id" => $model->office_id]); if (empty($office)) { $title = "--"; } else { $title = $office->title; } echo "<h1>渠道名称: " . $title . "</h1>"; echo "<h3>代金卷: " . MOfficeScoreEvent::getCatNameOption($model->cat) . "</h3>"; echo "<h3>减积分: " . $model->score . "</h3>"; echo "<h3>时间: " . $model->create_time . "</h3>"; ?> <br> <?php echo $form->field($model, 'status')->dropDownList(MOfficeScoreEvent::getOseStatusOption()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? '新增' : '修改', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
public static function confirmAjax($office_id, $cat) { $office = MOffice::findOne(['office_id' => $office_id]); if (empty($office)) { $score = 0; } else { $score = $office->score; } if ($cat == self::CAT_30YUAN_DAIJINJUAN) { $dh_score = self::CAT_30YUAN_DAIJINJUAN_SCORE; } else { if ($cat == self::CAT_100YUAN_DAIJINJUAN) { $dh_score = self::CAT_100YUAN_DAIJINJUAN_SCORE; } else { $dh_score = self::CAT_30YUAN_DAIJINJUAN_SCORE; } } if ($score < $dh_score) { U::W("----------score not enough--------"); return \yii\helpers\Json::encode(['code' => 1]); } else { $office_score_event = new MOfficeScoreEvent(); $office_score_event->gh_id = 'gh_03a74ac96138'; $office_score_event->openid = ''; $office_score_event->office_id = $office_id; $office_score_event->cat = $cat; $office_score_event->score = $dh_score; $office_score_event->memo = self::getCatNameOption($cat); $office_score_event->status = 0; $office_score_event->code = ''; $office_score_event->create_time = date('y-m-d h:i:s', time()); $office_score_event->save(false); $office = MOffice::findOne(['office_id' => $office_id]); $office->score = $office->score - $dh_score; $office->save(false); } return \yii\helpers\Json::encode(['code' => 0]); }
public function actionUpdate($id) { $model = MOrder::findOne($id); if (!$model) { throw new NotFoundHttpException('no this order'); } if (\Yii::$app->request->isPost) { $model->load(\Yii::$app->request->post()); if ($model->save(true, ['status', 'select_mobnum', 'memo_reply', 'wlgs', 'wldh'])) { $mobnum = MMobnum::findOne($model->select_mobnum); if ($mobnum !== null) { if ($model->status == MOrder::STATUS_SUCCEEDED) { $mobnum->status = MMobnum::STATUS_USED; } else { if ($model->status == MOrder::STATUS_SUBMITTED) { $mobnum->status = MMobnum::STATUS_LOCKED; } else { if ($model->status == MOrder::STATUS_BUYER_CLOSED) { $mobnum->status = MMobnum::STATUS_UNUSED; } } } $mobnum->save(false); } //会员(非自营厅渠道的)下单成功 STATUS_SUCCEEDED/STATUS_SYSTEM_SUCCEEDED时,非自营厅渠道要 +积分100 $user = MUser::findOne(['openid' => $model->openid]); $office = MOffice::findOne(['office_id' => $user->belongto]); if ($office->is_selfOperated == 0) { if ($model->status == MOrder::STATUS_SUCCEEDED) { //wx_office_score_event 增加一条记录 $offce_score_event = new MOfficeScoreEvent(); $offce_score_event->gh_id = $model->gh_id; $offce_score_event->openid = $model->openid; $offce_score_event->office_id = $user->belongto; $offce_score_event->cat = MOfficeScoreEvent::CAT_ADD_ORDER; $offce_score_event->create_time = date('y-m-d h:i:s', time()); $offce_score_event->score = MOfficeScoreEvent::CAT_ADD_ORDER_SCORE; $offce_score_event->memo = '会员订单'; $offce_score_event->save(false); //wx_office表中对应渠道score 加100分 $office->score = $office->score + 100; $office->save(false); } } return $this->redirect(['index']); } } return $this->render('update', ['model' => $model]); }
public static function closeExpiredOrders() { $tableName = MOrder::tableName(); $n = Yii::$app->db->createCommand()->delete($tableName, 'status=:status AND create_time < DATE_SUB(NOW(), INTERVAL 2 day)', [':status' => MOrder::STATUS_DRAFT])->execute(); U::W("UPDATE {$tableName}, {$n} --- 系统删除2天前的僵死订单。"); // auto close the orders exceed 2 days $n = Yii::$app->db->createCommand()->update($tableName, ['status' => MOrder::STATUS_SYSTEM_CLOSED], 'status=:status AND create_time < DATE_SUB(NOW(), INTERVAL 2 day)', [':status' => MOrder::STATUS_SUBMITTED])->execute(); U::W("UPDATE {$tableName}, {$n} --- 系统自动关闭超时2天的提交订单。"); $n = Yii::$app->db->createCommand()->update($tableName, ['status' => MOrder::STATUS_SYSTEM_SUCCEEDED], 'status=:status AND create_time < DATE_SUB(NOW(), INTERVAL 2 day)', [':status' => MOrder::STATUS_FULFILLED])->execute(); U::W("UPDATE {$tableName}, {$n} --- 系统自动确认超时2天的已办理订单。"); //找到超时2天的成功订单, 将其归属的渠道 +积分100 $orders = MOrder::find()->where(['status' => MOrder::STATUS_FULFILLED])->andWhere(['<', 'create_time', 'DATE_SUB(NOW(), INTERVAL 2 day)'])->all(); foreach ($orders as $order) { $user = MUser::findOne(['openid' => $order->openid]); $office = MOffice::findOne(['office_id' => $user->belongto]); if ($office->is_selfOperated == 0) { //wx_office_score_event 增加一条记录 $offce_score_event = new MOfficeScoreEvent(); $offce_score_event->gh_id = $order->gh_id; $offce_score_event->openid = $order->openid; $offce_score_event->office_id = $user->belongto; $offce_score_event->cat = MOfficeScoreEvent::CAT_ADD_ORDER; $offce_score_event->create_time = date('y-m-d h:i:s', time()); $offce_score_event->score = MOfficeScoreEvent::CAT_ADD_ORDER_SCORE; $offce_score_event->memo = '会员订单'; $offce_score_event->save(false); //wx_office表中对应渠道score 加100分 $office->score = $office->score + 100; $office->save(false); } } /* //move the unsuccessful orders exceed 90 days to bak table $n = Yii::$app->db->createCommand("INSERT INTO {$tableName}_arc SELECT * FROM $tableName WHERE status!=:status AND create_time < DATE_SUB(NOW(), INTERVAL 90 day)", [':status'=>MOrder::STATUS_OK])->execute(); U::W("INSERT $tableName, $n"); $n = Yii::$app->db->createCommand("DELETE FROM $tableName WHERE status!=:status AND create_time < DATE_SUB(NOW(), INTERVAL 90 day)", [':status'=>MOrder::STATUS_OK])->execute(); U::W("DELETE $tableName, $n"); */ //release mobile number $tableName = MMobnum::tableName(); $n = Yii::$app->db->createCommand()->update($tableName, ['status' => MMobnum::STATUS_UNUSED, 'locktime' => 0], 'status=:status AND locktime < :locktime', [':status' => MMobnum::STATUS_LOCKED, ':locktime' => time() - 2 * 24 * 3600])->execute(); U::W("UPDATE {$tableName}, {$n}"); $n = Yii::$app->db->createCommand("DELETE FROM {$tableName} WHERE status=:status", [':status' => MMobnum::STATUS_USED])->execute(); U::W("DELETE {$tableName}, {$n}"); }
<h1>渠道优惠券兑换管理</h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <!-- <p> <//?= Html::a('Create Moffice Score Event', ['create'], ['class' => 'btn btn-success']) ?> </p> --> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['label' => '渠道名称', 'value' => function ($model, $key, $index, $column) { //return MHd201509t6::gethd201509t6StatusOption($model->status); $office = app\models\MOffice::findOne(["office_id" => $model->office_id]); if (empty($office)) { return "--"; } else { return $office->title; } }, 'headerOptions' => array('style' => 'width:220px;')], 'create_time', 'score', 'memo', 'code', ['attribute' => 'status', 'label' => '审核状态', 'value' => function ($model, $key, $index, $column) { return MOfficeScoreEvent::getOseStatusOption($model->status); }, 'filter' => MOfficeScoreEvent::getOseStatusOption(), 'headerOptions' => array('style' => 'width:120px;')], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update}', 'buttons' => ['update' => function ($url, $model) { return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, ['title' => Yii::t('yii', 'Update'), 'data-pjax' => '0']); }]]]]); ?> </div>
/** * Finds the MOfficeScoreEvent model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MOfficeScoreEvent the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MOfficeScoreEvent::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
</div> <!-- /.modal-dialog --> </div> <?php } ?> <div class="modal fade in" id="office-score-event-modal" style="display: none;"> <?php if (null === $target_office) { $office_id = 0; } else { $office_id = $target_office->office_id; } $office_sore_events = \app\models\MOfficeScoreEvent::find()->where(['office_id' => $office_id])->orderBy(['create_time' => SORT_DESC])->limit(20)->all(); ?> <div class="modal-dialog"> <div class="modal-content" style="width:680px"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button> <h4 class="modal-title">渠道积分明细 (最近20条)</h4> <a class="btn btn-danger btn-lg" href='<?php echo \yii\helpers\Url::to(['office-score-event/office-index', 'office_id' => $office_id]); ?> '>优惠券兑换</a> </div> <div class="modal-body"> <div class="row">
public function actionAddbindmobile($gh_id, $openid) { $this->layout = 'wap'; $model = new OpenidBindMobile(); $model->gh_id = $gh_id; $model->openid = $openid; $model->setScenario('bind_mobile'); if ($model->load(Yii::$app->request->post()) && $model->save()) { //非自营厅渠道新增会员时,+积分100 $user = MUser::findOne(['openid' => $openid]); $office = MOffice::findOne(['office_id' => $user->belongto]); if (!empty($office)) { if ($office->is_selfOperated == 0) { //wx_office_score_event 增加一条记录 $offce_score_event = new MOfficeScoreEvent(); $offce_score_event->gh_id = $gh_id; $offce_score_event->openid = $openid; $offce_score_event->office_id = $user->belongto; $offce_score_event->cat = MOfficeScoreEvent::CAT_ADD_NEW_MEMBER; $offce_score_event->create_time = date('y-m-d h:i:s', time()); $offce_score_event->score = MOfficeScoreEvent::CAT_ADD_NEW_MEMBER_SCORE; $offce_score_event->memo = '新增会员'; $offce_score_event->save(false); //wx_office表中对应渠道score 加100分 $office->score = $office->score + 100; $office->save(false); } } Yii::$app->wx->setGhId($gh_id); $url = Url::to(['hyzx1', 'gh_id' => $gh_id, 'openid' => $openid], true); Yii::$app->wx->WxTemplateSend(Wechat::getTemplateBindSuccessNotify($openid, $url, "{$model->user->nickname},您的手机号码已成功绑定襄阳联通官方微信营业厅", "您已成为襄阳联通的会员,可随时查询话费余额,办理业务,参与更多专享优惠!", $model->mobile, date('Y-m-d'))); $url = Yii::$app->getSession()->get('RETURN_URL'); if (!empty($url)) { return $this->redirect($url); } else { Yii::$app->session->setFlash('success', '恭喜您,会员注册成功!'); return $this->refresh(); } } $searchModel = new OpenidBindMobileSearch(); $searchModel->gh_id = $gh_id; $searchModel->openid = $openid; $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('addbindmobile', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'model' => $model]); }
<//?= Html::a('Create Moffice Score Event', ['create'], ['class' => 'btn btn-success']) ?> </p> --> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'memo', 'score', 'create_time', 'code', ['attribute' => 'status', 'label' => '审核状态', 'format' => 'html', 'value' => function ($model, $key, $index, $column) { $flag = ""; if ($model->status == 1) { $flag = "<span class='glyphicon glyphicon-ok' style='color:green'></span>"; } else { if ($model->status == 2) { $flag = "<span class='glyphicon glyphicon-remove' style='color:red'></span>"; } } return MOfficeScoreEvent::getOseStatusOption($model->status) . " " . $flag; }, 'filter' => MOfficeScoreEvent::getOseStatusOption(), 'headerOptions' => array('style' => 'width:120px;')]]]); ?> </div> <script type="text/javascript"> $(document).ready(function() { $('#dyj30').click (function () { //alert('confirmAjax'); var cat =101; if (!confirm("确定要兑换吗?")) return;