正在显示
3 个修改的文件
包含
104 行增加
和
10 行删除
@@ -140,6 +140,23 @@ class Store extends Backend | @@ -140,6 +140,23 @@ class Store extends Backend | ||
140 | $auth_group_data['uid'] = $admin_model->id; | 140 | $auth_group_data['uid'] = $admin_model->id; |
141 | $result_auth_group = $auth_group_model->isUpdate(false)->save($auth_group_data); | 141 | $result_auth_group = $auth_group_model->isUpdate(false)->save($auth_group_data); |
142 | $row->allowField(true)->isUpdate(true)->save(['admin_id'=>$admin_model->id]); | 142 | $row->allowField(true)->isUpdate(true)->save(['admin_id'=>$admin_model->id]); |
143 | + // 新增社区有效期 | ||
144 | + $time = time(); | ||
145 | + foreach (explode(',',$row->house_ids) as $v) { | ||
146 | + $insert = [ | ||
147 | + 'user_id' => $row->user_id, | ||
148 | + 'store_id' => $row->id, | ||
149 | + 'house_id' => $v, | ||
150 | + 'start_time' => $time, | ||
151 | + 'end_time' => $time + config('site.house_valid'), | ||
152 | + 'createtime' => $time, | ||
153 | + 'updatetime' => $time | ||
154 | + ]; | ||
155 | + $result_store_house = Db::name('store_house')->insertGetId($insert); | ||
156 | + if(!$result_store_house) { | ||
157 | + Db::rollback(); | ||
158 | + } | ||
159 | + } | ||
143 | } | 160 | } |
144 | if($params['status'] == 4) { | 161 | if($params['status'] == 4) { |
145 | // 审核不通过,执行退款操作 | 162 | // 审核不通过,执行退款操作 |
@@ -550,6 +550,7 @@ class Store extends Api | @@ -550,6 +550,7 @@ class Store extends Api | ||
550 | "name"://小区名称 | 550 | "name"://小区名称 |
551 | "area"://所在区 | 551 | "area"://所在区 |
552 | "address"://地址 | 552 | "address"://地址 |
553 | + "days"://剩余天数 | ||
553 | } | 554 | } |
554 | ] | 555 | ] |
555 | } | 556 | } |
@@ -559,22 +560,34 @@ class Store extends Api | @@ -559,22 +560,34 @@ class Store extends Api | ||
559 | { | 560 | { |
560 | $store = $this->get_store(); | 561 | $store = $this->get_store(); |
561 | $where = [ | 562 | $where = [ |
562 | - 'id' => ['in',$store['house_ids']] | 563 | + 'sh.user_id' => $this->auth->id, |
564 | + 'sh.store_id' => $store['id'], | ||
563 | ]; | 565 | ]; |
564 | $area = $this->request->param('area'); | 566 | $area = $this->request->param('area'); |
565 | $keyword = $this->request->param('keyword'); | 567 | $keyword = $this->request->param('keyword'); |
566 | if(!empty($area)){ | 568 | if(!empty($area)){ |
567 | - $where['area'] = ['like',"%$area%"]; | 569 | + $where['h.area'] = ['like',"%$area%"]; |
568 | } | 570 | } |
569 | if(!empty($keyword)){ | 571 | if(!empty($keyword)){ |
570 | - $where['name'] = ['like',"%$keyword%"]; | 572 | + $where['h.name'] = ['like',"%$keyword%"]; |
571 | } | 573 | } |
572 | - $data = Db::name('house') | ||
573 | - ->where($where) | ||
574 | - ->field('id,name,area,address') | ||
575 | - ->order('createtime desc') | ||
576 | - ->select(); | ||
577 | - $this->success('success',$data); | 574 | + $store_house = Db::name('store_house')->alias('sh') |
575 | + ->field('sh.end_time,h.id,h.name,h.area,h.address') | ||
576 | + ->join('__HOUSE__ h','sh.house_id = h.id') | ||
577 | + ->where($where)->select(); | ||
578 | + $time = time(); | ||
579 | + foreach ($store_house as &$v) { | ||
580 | + $v['days'] = $v['end_time'] > $time ? floor(($v['end_time'] - $time) / 86400) : 0; | ||
581 | + } | ||
582 | +// $where = [ | ||
583 | +// 'id' => ['in',$store_house] | ||
584 | +// ]; | ||
585 | +// $data = Db::name('house') | ||
586 | +// ->where($where) | ||
587 | +// ->field('id,name,area,address') | ||
588 | +// ->order('createtime desc') | ||
589 | +// ->select(); | ||
590 | + $this->success('success',$store_house); | ||
578 | } | 591 | } |
579 | 592 | ||
580 | /** | 593 | /** |
@@ -1035,6 +1048,39 @@ class Store extends Api | @@ -1035,6 +1048,39 @@ class Store extends Api | ||
1035 | 'house_ids' => $store['house_ids'].','.$param['house_ids'].',' | 1048 | 'house_ids' => $store['house_ids'].','.$param['house_ids'].',' |
1036 | ]; | 1049 | ]; |
1037 | $res_store = Db::name('store')->where('id',$param['store_id'])->update($update); | 1050 | $res_store = Db::name('store')->where('id',$param['store_id'])->update($update); |
1051 | + if(!$res_store) { | ||
1052 | + Db::rollback(); | ||
1053 | + } | ||
1054 | + $time = time(); | ||
1055 | + foreach (explode(',',$param['house_ids']) as $v) { | ||
1056 | + // 新增或修改社区有效期数据 | ||
1057 | + $store_house = Db::name('store_house')->where(['user_id'=>$this->auth->id,'store_id'=>$store['id'],'house_id'=>$v])->find(); | ||
1058 | + if($store_house) { | ||
1059 | + $house_update = [ | ||
1060 | + 'id' => $store_house['id'] | ||
1061 | + ]; | ||
1062 | + if($store_house['end_time'] > $time) { | ||
1063 | + $house_update['end_time'] = $store_house['end_time'] + config('site.house_valid'); | ||
1064 | + } else { | ||
1065 | + $house_update['end_time'] = $time + config('site.house_valid'); | ||
1066 | + } | ||
1067 | + $result_store_house = Db::name('store_house')->update(['id'=>$store_house['id'],'']); | ||
1068 | + } else { | ||
1069 | + $insert = [ | ||
1070 | + 'user_id' => $param['user_id'], | ||
1071 | + 'store_id' => $param['store_id'], | ||
1072 | + 'house_id' => $v, | ||
1073 | + 'start_time' => $time, | ||
1074 | + 'end_time' => $time + config('site.house_valid'), | ||
1075 | + 'createtime' => $time, | ||
1076 | + 'updatetime' => $time | ||
1077 | + ]; | ||
1078 | + $result_store_house = Db::name('store_house')->insertGetId($insert); | ||
1079 | + } | ||
1080 | + if(!$result_store_house) { | ||
1081 | + Db::rollback(); | ||
1082 | + } | ||
1083 | + } | ||
1038 | } | 1084 | } |
1039 | Db::commit(); | 1085 | Db::commit(); |
1040 | } catch (PDOException $e) { | 1086 | } catch (PDOException $e) { |
@@ -164,9 +164,10 @@ class Ajax extends Frontend | @@ -164,9 +164,10 @@ class Ajax extends Frontend | ||
164 | if ($successful) { | 164 | if ($successful) { |
165 | Db::startTrans(); | 165 | Db::startTrans(); |
166 | // 回填微信的订单号 | 166 | // 回填微信的订单号 |
167 | + $time = time(); | ||
167 | $update['transaction_id'] = $notify->transaction_id; | 168 | $update['transaction_id'] = $notify->transaction_id; |
168 | $update['status'] = 2; //付款成功 | 169 | $update['status'] = 2; //付款成功 |
169 | - $update['pay_time'] = time(); | 170 | + $update['pay_time'] = $time; |
170 | //更新状态: 已购买 | 171 | //更新状态: 已购买 |
171 | $res_order = Db::name('store_order')->where(['id' => $info['id']])->update($update); | 172 | $res_order = Db::name('store_order')->where(['id' => $info['id']])->update($update); |
172 | // 新增关联社区 | 173 | // 新增关联社区 |
@@ -174,6 +175,36 @@ class Ajax extends Frontend | @@ -174,6 +175,36 @@ class Ajax extends Frontend | ||
174 | 'house_ids' => $store['house_ids'].','.$info['house_ids'].',' | 175 | 'house_ids' => $store['house_ids'].','.$info['house_ids'].',' |
175 | ]; | 176 | ]; |
176 | $res_store = Db::name('store')->where('id',$info['store_id'])->update($update); | 177 | $res_store = Db::name('store')->where('id',$info['store_id'])->update($update); |
178 | + // 修改或新增社区有效期 | ||
179 | + foreach (explode(',',$info['house_ids']) as $v) { | ||
180 | + $store_house = Db::name('store_house')->where(['user_id'=>$info['user_id'],'store_id'=>$info['store_id'],'house_id'=>$v])->find(); | ||
181 | + if($store_house) { | ||
182 | + $house_update = [ | ||
183 | + 'id' => $store_house['id'] | ||
184 | + ]; | ||
185 | + if($store_house['end_time'] > $time) { | ||
186 | + $house_update['end_time'] = $store_house['end_time'] + config('site.house_valid'); | ||
187 | + } else { | ||
188 | + $house_update['end_time'] = $time + config('site.house_valid'); | ||
189 | + } | ||
190 | + $result_store_house = Db::name('store_house')->update(['id'=>$store_house['id'],'']); | ||
191 | + } else { | ||
192 | + $insert = [ | ||
193 | + 'user_id' => $info['user_id'], | ||
194 | + 'store_id' => $info['store_id'], | ||
195 | + 'house_id' => $v, | ||
196 | + 'start_time' => $time, | ||
197 | + 'end_time' => $time + config('site.house_valid'), | ||
198 | + 'createtime' => $time, | ||
199 | + 'updatetime' => $time | ||
200 | + ]; | ||
201 | + $result_store_house = Db::name('store_house')->insertGetId($insert); | ||
202 | + } | ||
203 | + if(!$result_store_house) { | ||
204 | + Db::rollback(); | ||
205 | + return false; // 返回处理完成 | ||
206 | + } | ||
207 | + } | ||
177 | if(!$res_order || !$res_store) { | 208 | if(!$res_order || !$res_store) { |
178 | Db::rollback(); | 209 | Db::rollback(); |
179 | return false; // 返回处理完成 | 210 | return false; // 返回处理完成 |
-
请 注册 或 登录 后发表评论