Sellerindex.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. namespace app\api\controller;
  3. /**
  4. *
  5. *
  6. * ----------------------------------------------------------------------------
  7. *
  8. * 卖家中心控制器
  9. */
  10. class Sellerindex extends MobileSeller
  11. {
  12. public function initialize()
  13. {
  14. parent::initialize(); // TODO: Change the autogenerated stub
  15. }
  16. /**
  17. * @api {POST} api/Sellerindex/index 商家中心
  18. * @apiVersion 1.0.0
  19. * @apiGroup Sellerindex
  20. *
  21. * @apiHeader {String} X-DS-KEY 卖家授权token
  22. *
  23. * @apiSuccess {String} code 返回码,10000为成功
  24. * @apiSuccess {String} message 返回消息
  25. * @apiSuccess {Object} result 返回数据
  26. * @apiSuccess {Object} result.seller_info 卖家信息
  27. * @apiSuccess {Int} result.seller_info.goods_lockup 违规商品数
  28. * @apiSuccess {Int} result.seller_info.goods_offline 下架商品数
  29. * @apiSuccess {Int} result.seller_info.goods_online 上架商品数
  30. * @apiSuccess {Int} result.seller_info.is_admin 是否主账号 0否1是
  31. * @apiSuccess {Int} result.seller_info.last_logintime 上次登录时间
  32. * @apiSuccess {Int} result.seller_info.last_logintime_fmt 上次登录时间描述
  33. * @apiSuccess {Int} result.seller_info.member_id 用户ID
  34. * @apiSuccess {Int} result.seller_info.order_nopay_count 待付款订单数
  35. * @apiSuccess {Int} result.seller_info.order_noreceipt_count 待收货订单数
  36. * @apiSuccess {Int} result.seller_info.order_noship_count 待发货订单数
  37. * @apiSuccess {Int} result.seller_info.seller_clienttype 客户端
  38. * @apiSuccess {Int} result.seller_info.seller_id 卖家账号ID
  39. * @apiSuccess {Int} result.seller_info.seller_name 卖家账号名称
  40. * @apiSuccess {Int} result.seller_info.sellergroup_id 卖家账号组
  41. * @apiSuccess {Int} result.seller_info.store_id 店铺ID
  42. * @apiSuccess {Object} result.statics 统计信息
  43. * @apiSuccess {Int} result.statics.bill_confirm 待确认结算单数
  44. * @apiSuccess {Int} result.statics.complain 投诉数
  45. * @apiSuccess {Int} result.statics.consult 咨询数
  46. * @apiSuccess {Int} result.statics.delivery 待发货订单数
  47. * @apiSuccess {Int} result.statics.goodscount 商品数
  48. * @apiSuccess {Int} result.statics.imagecount 图片数
  49. * @apiSuccess {Int} result.statics.lockup 违商品规数
  50. * @apiSuccess {Int} result.statics.offline 下架商品数
  51. * @apiSuccess {Int} result.statics.online 上架商品数
  52. * @apiSuccess {Int} result.statics.payment 已付款订单数
  53. * @apiSuccess {Int} result.statics.progressing 交易中订单数
  54. * @apiSuccess {Int} result.statics.refund 退款数
  55. * @apiSuccess {Int} result.statics.refund_lock 退款中数
  56. * @apiSuccess {Int} result.statics.return 退货数
  57. * @apiSuccess {Int} result.statics.return_lock 退货中数
  58. * @apiSuccess {Int} result.statics.verifyfail 审核失败商品数
  59. * @apiSuccess {Int} result.statics.waitverify 等待审核商品数
  60. * @apiSuccess {Object} result.store_info 店铺信息 (返回字段参考store表)
  61. * @apiSuccess {Object} result.store_info.daily_sales 今日销量
  62. * @apiSuccess {Float} result.store_info.daily_sales.orderamount 订单金额
  63. * @apiSuccess {Int} result.store_info.daily_sales.ordernum 订单量
  64. * @apiSuccess {Int} result.store_info.goods_count 商品数量
  65. * @apiSuccess {Int} result.store_info.grade_albumlimit 商品图片限制,0不限制
  66. * @apiSuccess {Int} result.store_info.grade_goodslimit 商品数量限制,0不限制
  67. * @apiSuccess {Int} result.store_info.grade_id 店铺等级
  68. * @apiSuccess {Int} result.store_info.grade_name 店铺等级名称
  69. * @apiSuccess {Object} result.store_info.monthly_sales 月销量
  70. * @apiSuccess {Float} result.store_info.monthly_sales.orderamount 订单金额
  71. * @apiSuccess {Int} result.store_info.monthly_sales.ordernum 订单量
  72. */
  73. public function index()
  74. {
  75. $seller_info = array();
  76. $seller_info = $this->seller_info;
  77. $store_info = $this->store_info;
  78. //最后登陆
  79. $seller_info['last_logintime_fmt'] = date('Y-m-d H:i:s', $seller_info['last_logintime']);
  80. $order_model = model('order');
  81. // 待付款
  82. $seller_info['order_nopay_count'] = intval($order_model->getOrderCountByID('store', $store_info['store_id'], 'NewCount'));
  83. // 待发货
  84. $seller_info['order_noship_count'] = intval($order_model->getOrderCountByID('store', $store_info['store_id'], 'PayCount'));
  85. // 待收货
  86. $seller_info['order_noreceipt_count'] = intval($order_model->getOrderCountByID('store', $store_info['store_id'], 'SendCount'));
  87. $goods_model = model('goods');
  88. // 出售中的商品
  89. $seller_info['goods_online'] = $goods_model->getGoodsCommonOnlineCount(array(array('store_id', '=', $store_info['store_id'])));
  90. // 仓库待上架的商品
  91. $seller_info['goods_offline'] = $goods_model->getGoodsCommonOfflineCount(array(array('store_id', '=', $store_info['store_id'])));
  92. // 违规下架的商品
  93. $seller_info['goods_lockup'] = $goods_model->getGoodsCommonLockUpCount(array(array('store_id', '=', $store_info['store_id'])));
  94. //店铺头像
  95. $store_info['store_avatar'] = get_store_logo($store_info['store_avatar'], 'store_avatar');
  96. //店铺标志
  97. $store_info['store_logo'] = get_store_logo($store_info['store_logo'], 'store_logo');
  98. //等级信息
  99. $store_info['grade_name'] = $this->store_grade['storegrade_name'];
  100. //商品数量限制
  101. $store_info['grade_goodslimit'] = $this->store_grade['storegrade_goods_limit'];
  102. //图片空间数量限制
  103. $store_info['grade_albumlimit'] = $this->store_grade['storegrade_album_limit'];
  104. /**
  105. * 销售情况统计
  106. */
  107. $field = 'COUNT(*) as ordernum,SUM(order_amount) as orderamount';
  108. $where = array();
  109. $where[] = array('store_id', '=', $this->store_info['store_id']);
  110. //有效订单
  111. $where[] = array('order_isvalid', '=', 1);
  112. //昨日销量
  113. $where[] = array('order_add_time', 'between', array(strtotime(date('Y-m-d', (TIMESTAMP - 3600 * 24))), strtotime(date('Y-m-d', TIMESTAMP)) - 1));
  114. $daily_sales = model('stat')->getoneByStatorder($where, $field);
  115. //月销量
  116. $where[] = array('order_add_time', '>', strtotime(date('Y-m', TIMESTAMP)));
  117. $monthly_sales = model('stat')->getoneByStatorder($where, $field);
  118. $store_info['daily_sales'] = $daily_sales;
  119. $store_info['monthly_sales'] = $monthly_sales;
  120. //统计
  121. $statics = $this->getStatics();
  122. ds_json_encode(10000, '', array('seller_info' => $seller_info, 'store_info' => $store_info, 'statics' => $statics));
  123. }
  124. /**
  125. * @api {POST} api/Sellerindex/getStatics 取得卖家统计类信息
  126. * @apiVersion 1.0.0
  127. * @apiGroup Sellerindex
  128. *
  129. * @apiHeader {String} X-DS-KEY 卖家授权token
  130. *
  131. * @apiSuccess {String} code 返回码,10000为成功
  132. * @apiSuccess {String} message 返回消息
  133. * @apiSuccess {Object} result 返回数据
  134. */
  135. private function getStatics()
  136. {
  137. $add_time_to = strtotime(date("Y-m-d")) + 60 * 60 * 24; //当前日期 ,从零点来时
  138. $add_time_from = strtotime(date("Y-m-d", (strtotime(date("Y-m-d")) - 60 * 60 * 24 * 30))); //30天前
  139. $goods_online = 0; // 出售中商品
  140. $goods_waitverify = 0; // 等待审核
  141. $goods_verifyfail = 0; // 审核失败
  142. $goods_offline = 0; // 仓库待上架商品
  143. $goods_lockup = 0; // 违规下架商品
  144. $consult = 0; // 待回复商品咨询
  145. $no_payment = 0; // 待付款
  146. $no_delivery = 0; // 待发货
  147. $no_receipt = 0; // 待收货
  148. $refund_lock = 0; // 售前退款
  149. $refund = 0; // 售后退款
  150. $return_lock = 0; // 售前退货
  151. $return = 0; // 售后退货
  152. $complain = 0; //进行中投诉
  153. $goods_model = model('goods');
  154. // 全部商品数
  155. $goodscount = $goods_model->getGoodsCommonCount(array('store_id' => $this->store_info['store_id']));
  156. // 出售中的商品
  157. $goods_online = $goods_model->getGoodsCommonOnlineCount(array(array('store_id', '=', $this->store_info['store_id'])));
  158. if (config('ds_config.goods_verify')) {
  159. // 等待审核的商品
  160. $goods_waitverify = $goods_model->getGoodsCommonWaitVerifyCount(array(array('store_id', '=', $this->store_info['store_id'])));
  161. // 审核失败的商品
  162. $goods_verifyfail = $goods_model->getGoodsCommonVerifyFailCount(array(array('store_id', '=', $this->store_info['store_id'])));
  163. }
  164. // 仓库待上架的商品
  165. $goods_offline = $goods_model->getGoodsCommonOfflineCount(array(array('store_id', '=', $this->store_info['store_id'])));
  166. // 违规下架的商品
  167. $goods_lockup = $goods_model->getGoodsCommonLockUpCount(array(array('store_id', '=', $this->store_info['store_id'])));
  168. // 等待回复商品咨询
  169. $consult = model('consult')->getConsultCount(array('store_id' => $this->store_info['store_id'], 'consult_reply' => ''));
  170. // 商品图片数量
  171. $imagecount = model('album')->getAlbumpicCount(array('store_id' => $this->store_info['store_id']));
  172. $order_model = model('order');
  173. // 交易中的订单
  174. $progressing = $order_model->getOrderCountByID('store', $this->store_info['store_id'], 'TradeCount');
  175. // 待付款
  176. $no_payment = $order_model->getOrderCountByID('store', $this->store_info['store_id'], 'NewCount');
  177. // 待发货
  178. $no_delivery = $order_model->getOrderCountByID('store', $this->store_info['store_id'], 'PayCount');
  179. $refundreturn_model = model('refundreturn');
  180. // 售前退款
  181. $condition = array();
  182. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  183. $condition[] = array('refund_type', '=', 1);
  184. $condition[] = array('order_lock', '=', 2);
  185. $condition[] = array('refund_state', '<', 3);
  186. $refund_lock = $refundreturn_model->getRefundreturnCount($condition);
  187. // 售后退款
  188. $condition = array();
  189. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  190. $condition[] = array('refund_type', '=', 1);
  191. $condition[] = array('order_lock', '=', 1);
  192. $condition[] = array('refund_state', '<', 3);
  193. $refund = $refundreturn_model->getRefundreturnCount($condition);
  194. // 售前退货
  195. $condition = array();
  196. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  197. $condition[] = array('refund_type', '=', 2);
  198. $condition[] = array('order_lock', '=', 2);
  199. $condition[] = array('refund_state', '<', 3);
  200. $return_lock = $refundreturn_model->getRefundreturnCount($condition);
  201. // 售后退货
  202. $condition = array();
  203. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  204. $condition[] = array('refund_type', '=', 2);
  205. $condition[] = array('order_lock', '=', 1);
  206. $condition[] = array('refund_state', '<', 3);
  207. $return = $refundreturn_model->getRefundreturnCount($condition);
  208. $condition = array();
  209. $condition[] = array('accused_id', '=', $this->store_info['store_id']);
  210. $condition[] = array('complain_state', 'between', array(10, 90));
  211. $complain_model = model('complain');
  212. $complain = $complain_model->getComplainCount($condition);
  213. //待确认的结算账单
  214. $bill_model = model('bill');
  215. $condition = array();
  216. $condition[] = array('ob_store_id', '=', $this->store_info['store_id']);
  217. $condition[] = array('ob_state', '=', BILL_STATE_CREATE);
  218. $bill_confirm_count = $bill_model->getOrderbillCount($condition);
  219. //统计数组
  220. $statistics = array(
  221. 'goodscount' => $goodscount,
  222. 'online' => $goods_online,
  223. 'waitverify' => $goods_waitverify,
  224. 'verifyfail' => $goods_verifyfail,
  225. 'offline' => $goods_offline,
  226. 'lockup' => $goods_lockup,
  227. 'imagecount' => $imagecount,
  228. 'consult' => $consult,
  229. 'progressing' => $progressing,
  230. 'payment' => $no_payment,
  231. 'delivery' => $no_delivery,
  232. 'refund_lock' => $refund_lock,
  233. 'refund' => $refund,
  234. 'return_lock' => $return_lock,
  235. 'return' => $return,
  236. 'complain' => $complain,
  237. 'bill_confirm' => $bill_confirm_count
  238. );
  239. return $statistics;
  240. }
  241. }