123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- namespace app\common\model;
- use think\facade\Db;
- class Ppintuangroup extends BaseModel {
- public $page_info;
- const PINTUANGROUP_STATE_CLOSE = 0;
- const PINTUANGROUP_STATE_NORMAL = 1;
- const PINTUANGROUP_STATE_SUCCESS = 2;
- private $pintuangroup_state_array = array(
- self::PINTUANGROUP_STATE_CLOSE => '拼团取消',
- self::PINTUANGROUP_STATE_NORMAL => '参团中',
- self::PINTUANGROUP_STATE_SUCCESS => '拼团成功'
- );
-
- public function getPpintuangroupList($condition, $pagesize = '',$order='pintuangroup_starttime desc') {
- $field = "ppintuangroup.*,member.member_name";
- if ($pagesize) {
- $result = Db::name('ppintuangroup')->alias('ppintuangroup')->join('member member','ppintuangroup.pintuangroup_headid=member.member_id')->field($field)->where($condition)->order($order)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
- $this->page_info = $result;
- $ppintuangroup_list = $result->items();
- }else{
- $ppintuangroup_list = Db::name('ppintuangroup')->alias('ppintuangroup')->join('member member','ppintuangroup.pintuangroup_headid=member.member_id')->field($field)->where($condition)->order($order)->select()->toArray();
- }
- if (!empty($ppintuangroup_list)) {
- foreach ($ppintuangroup_list as $key => $ppintuangroup) {
-
- $pintuangroup_surplus = $ppintuangroup['pintuangroup_limit_number'] - $ppintuangroup['pintuangroup_joined'];
- $ppintuangroup_list[$key]['pintuangroup_state_text'] = $this->pintuangroup_state_array[$ppintuangroup['pintuangroup_state']];
- $ppintuangroup_list[$key]['pintuangroup_surplus'] = $pintuangroup_surplus;
- $ppintuangroup_list[$key]['pintuangroup_avatar'] = get_member_avatar_for_id($ppintuangroup['pintuangroup_headid']);
- }
- }
- return $ppintuangroup_list;
- }
-
- public function getOnePpintuangroup($condition){
- return Db::name('ppintuangroup')->where($condition)->find();
- }
-
-
- public function addPpintuangroup($data)
- {
- return Db::name('ppintuangroup')->insertGetId($data);
- }
-
-
- public function editPpintuangroup($condition,$data)
- {
- return Db::name('ppintuangroup')->where($condition)->update($data);
- }
-
-
- public function successPpintuangroup($condition,$condition2)
- {
-
- $update_group['pintuangroup_state'] = 2;
- $update_group['pintuangroup_endtime'] = TIMESTAMP;
- $this->editPpintuangroup($condition, $update_group);
-
- $update_order['pintuanorder_state'] = 2;
- model('ppintuanorder')->editPpintuanorder($condition2,$update_order);
- }
-
-
- public function failPpintuangroup($condition)
- {
-
- $update_group['pintuangroup_state'] = 0;
- $update_group['pintuangroup_endtime'] = TIMESTAMP;
- $this->editPpintuangroup($condition, $update_group);
-
- $update_order['pintuanorder_state'] = 0;
- model('ppintuanorder')->editPpintuanorder($condition,$update_order);
- }
-
-
- public function getPintuangroupStateArray() {
- return $this->pintuangroup_state_array;
- }
-
- }
|