SpecialBuy.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\special;
  12. use basic\ModelBasic;
  13. use traits\ModelTrait;
  14. class SpecialBuy extends ModelBasic
  15. {
  16. use ModelTrait;
  17. protected function setAddTimeAttr()
  18. {
  19. return time();
  20. }
  21. protected function getAddTimeAttr($value)
  22. {
  23. return date('Y-m-d H:i:s', $value);
  24. }
  25. protected function getTypeAttr($value)
  26. {
  27. $name = '';
  28. switch ($value) {
  29. case 0:
  30. $name = '支付获得';
  31. break;
  32. case 1:
  33. $name = '拼团获得';
  34. break;
  35. case 2:
  36. $name = '领取礼物获得';
  37. break;
  38. case 3:
  39. $name = '赠送获得';
  40. break;
  41. }
  42. return $name;
  43. }
  44. public static function setAllBuySpecial($order_id, $uid, $special_id, $type = 0)
  45. {
  46. if (!$order_id || !$uid || !$special_id) return false;
  47. //如果是专栏,记录专栏下所有专题购买。
  48. $special = Special::get($special_id);
  49. if ($special['type'] == SPECIAL_COLUMN) {
  50. $special_source = SpecialSource::getSpecialSource($special['id']);
  51. if ($special_source){
  52. foreach($special_source as $k => $v) {
  53. $task_special = Special::get($v['source_id']);
  54. if ($task_special['is_show'] == 1){
  55. self::setBuySpecial($order_id, $uid, $v['source_id'], $type,$special_id);
  56. }
  57. }
  58. }
  59. self::setBuySpecial($order_id, $uid, $special_id, $type);
  60. }else{
  61. self::setBuySpecial($order_id, $uid, $special_id, $type);
  62. }
  63. }
  64. public static function setBuySpecial($order_id, $uid, $special_id, $type = 0,$column_id=0)
  65. {
  66. $add_time = time();
  67. if (self::be(['order_id' => $order_id, 'uid' => $uid, 'special_id' => $special_id, 'type' => 0,'column_id'=>$column_id])) return false;
  68. return self::set(compact('order_id','column_id','uid', 'special_id', 'type', 'add_time'));
  69. }
  70. /**专栏更新数据
  71. * @param $special_id
  72. */
  73. public static function columnUpdate($special_id){
  74. if (self::be(['special_id' => $special_id, 'is_del' => 0])){
  75. $special = Special::get($special_id);
  76. $column=self::where(['special_id'=>$special_id,'is_del'=>0])->field('id,order_id,column_id,uid,special_id,is_del,type as types')->select();
  77. $column=count($column) > 0 ? $column->toArray() : [];
  78. foreach ($column as $key=>$value){
  79. $sourceList=self::where(['order_id'=>$value['order_id'],'is_del'=>0,'uid'=>$value['uid'],'column_id'=>$special_id,'type'=>$value['types']])->select();
  80. $sourceList=count($sourceList) > 0 ? $sourceList->toArray() : [];
  81. if(count($sourceList)>0){
  82. $res=self::where(['order_id'=>$value['order_id'],'is_del'=>0,'uid'=>$value['uid'],'column_id'=>$special_id,'type'=>$value['types']])->delete();
  83. if($res){
  84. $special_source = SpecialSource::getSpecialSource($special['id']);
  85. if ($special_source){
  86. foreach($special_source as $k => $v) {
  87. $task_special = Special::get($v['source_id']);
  88. if ($task_special['is_show'] == 1){
  89. self::setBuySpecial($value['order_id'], $value['uid'], $v['source_id'], $value['types'],$special_id);
  90. }else{
  91. continue;
  92. }
  93. }
  94. }else{
  95. continue;
  96. }
  97. }else{
  98. continue;
  99. }
  100. }else{
  101. continue;
  102. }
  103. }
  104. }else{
  105. return true;
  106. }
  107. }
  108. public static function PaySpecial($special_id, $uid)
  109. {
  110. return self::where(['uid' => $uid, 'special_id' => $special_id, 'is_del' => 0])->count() ? true : false;
  111. }
  112. public static function getPayList($where)
  113. {
  114. $list = self::where(['a.uid' => $where['uid']])->alias('a')->join('__SPECIAL__ s', 's.id=a.special_id')
  115. ->field('a.*,s.title')->order('a.add_time desc')->page((int)$where['page'], (int)$where['limit'])->select();
  116. foreach ($list as &$item) {
  117. $pay_price=self::getDb('store_order')->where('order_id', $item['order_id'])->value('pay_price');
  118. $item['pay_price'] = $pay_price > 0 ? $pay_price : 0;
  119. }
  120. return $list;
  121. }
  122. }