Entrust.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 委托购买
  7. */
  8. namespace app\fastshop\model;
  9. use think\Model;
  10. class Entrust extends Model{
  11. protected $pk = 'id';
  12. protected $table = 'ai_fastshop_entrust';
  13. protected $table_entrust = 'ai_fastshop_entrust_list'; //寄卖商品表
  14. protected $autoWriteTimestamp = true;
  15. protected $createTime = false;
  16. /**
  17. * 商品基础库
  18. * @return void
  19. */
  20. public function item(){
  21. return $this->hasOne('Item','id','item_id');
  22. }
  23. /**
  24. * 成交管理
  25. */
  26. public function entrustList(array $condition){
  27. return self::view('fastshop_entrust','*')
  28. ->view('fastshop_item','img,name','fastshop_entrust.item_id = fastshop_item.id')->where($condition)->order('fastshop_entrust.gite_count desc')
  29. ->paginate(10);
  30. }
  31. /**
  32. * 小程序管理中心寄卖管理
  33. */
  34. public function giftManagelist(array $condition,int $types = 0,$keyword = ''){
  35. switch ($types) {
  36. case 1:
  37. $condition['fastshop_entrust_list.is_rebate'] = 0;
  38. break;
  39. case 2:
  40. $condition['fastshop_entrust_list.is_rebate'] = 1;
  41. case 3:
  42. $condition['fastshop_entrust_list.is_rebate'] = 1;
  43. $condition['fastshop_entrust_list.is_diy'] = 1;
  44. break;
  45. }
  46. return self::view('fastshop_entrust_list','id,item_id,entrust_price,rebate,is_rebate,user_id,create_time,is_under,update_time')
  47. ->view('system_user','nickname,face','fastshop_entrust_list.user_id = system_user.id','left')
  48. ->view('fastshop_item','img,name','fastshop_entrust_list.item_id = fastshop_item.id')->where($condition)->order('fastshop_entrust_list.id desc')
  49. ->paginate(10,false,['query' =>['types' => $types,'keyword' => $keyword]]);
  50. }
  51. /**
  52. * 用户寄卖列表(API) (V2.0待删除)
  53. */
  54. public function giftlist(int $uid,int $types = 0){
  55. $condition['fastshop_entrust_list.user_id'] = $uid;
  56. switch ($types) {
  57. case 1:
  58. $condition['fastshop_entrust_list.is_rebate'] = 0;
  59. break;
  60. case 2:
  61. $condition['fastshop_entrust_list.is_rebate'] = 1;
  62. break;
  63. }
  64. $info = self::view('fastshop_entrust_list','id,item_id,entrust_price,rebate,is_rebate,is_under')
  65. ->view('fastshop_item','img,name','fastshop_entrust_list.item_id = fastshop_item.id')->where($condition)->order('fastshop_entrust_list.id desc')
  66. ->paginate(10,true)->toArray();
  67. $data = [];
  68. foreach ($info['data'] as $key => $value) {
  69. $data[$key] = $value;
  70. $data[$key]['is_under'] = empty($value['is_under']) ? 0 : 1;
  71. $data[$key]['entrust_price'] = money($value['entrust_price']/100);
  72. $data[$key]['rebate'] = money($value['rebate']/100);
  73. $data[$key]['service_price'] = money($value['rebate']/100);
  74. $data[$key]['img'] = $value['img'];
  75. }
  76. return $data;
  77. }
  78. }