Consult.php 124 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //竞价单(咨询单)
  9. class Consult extends Base
  10. {
  11. public $noble=[];
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->noble =\think\facade\Config::get("noble");
  16. }
  17. public function conlist(){
  18. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  19. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  20. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  21. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  22. if ($infoNo !== "") {
  23. $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
  24. }
  25. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  26. if ($salesman !== "") {
  27. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  28. $where[]= ["b.salesman",'like',"%$salesman%"];
  29. }
  30. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  31. if ($cpName !== "") {
  32. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  33. $where[]= ["a.good_Name",'like',"%$cpName%"];
  34. }
  35. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  36. if ($khNo !== "") {
  37. // $where['khNo'] = $khNo;
  38. $where[]= ["b.khNo",'like',"%$khNo%"];
  39. }
  40. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  41. if ($companyNo !== "") {
  42. // $where['khNo'] = $khNo;
  43. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  44. }
  45. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  46. if ($start !="") {
  47. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  48. $where[]= ["a.addtime",'>=',$start];
  49. }
  50. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  51. if($end !=""){
  52. $where[]= ["a.addtime",'<=',$end];
  53. }
  54. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  55. if ($status !== "") {
  56. $where[]= ["a.status",'=',$status];
  57. }
  58. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  59. if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  60. $role=$this->checkRole();
  61. if(!empty($role['write'])){
  62. $where[]=["b.createrid","in",$role['write']];
  63. }
  64. // if(!empty($role['platform']) ){
  65. // $where[]=["b.platform_code","in",$role['platform']];
  66. // }
  67. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  68. ->count();
  69. $total = ceil($count / $size);
  70. $page = $page >= $total ? $total : $page;
  71. $list = Db::name('consult_info')
  72. ->alias("a")
  73. ->leftJoin("consult_order b", "a.zxNo=b.zxNo")
  74. ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
  75. ->where($where)
  76. ->page($page, $size)
  77. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart,u.itemid")
  78. ->order("a.id desc")
  79. ->cursor();
  80. $data=[];
  81. foreach ($list as $value){
  82. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  83. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  84. true):[];
  85. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  86. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  87. $value['khname']="";
  88. if($value['khNo']!==""){
  89. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  90. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  91. }
  92. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  93. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  94. $data[]=$value;
  95. }
  96. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  97. }
  98. public function info(){
  99. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  100. if($id==""){
  101. return error_show(1002,"咨询单编号不能为空");
  102. }
  103. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  104. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  105. $fo['can']=$in;
  106. if(empty($fo)){
  107. return error_show(1002,"未找到咨询单编号");
  108. }else{
  109. return app_show(0,"获取成功",$fo);
  110. }
  111. }
  112. public function del(){
  113. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  114. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  115. if($de==false){
  116. return error_show(1002,'咨询单信息未找到');
  117. }
  118. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  119. if($dell){
  120. return error_show(0,"删除成功");
  121. }else
  122. return error_show(1002,"删除失败");
  123. }
  124. public function create(){
  125. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  126. if($is_project===""){
  127. return error_show(1002,"参数is_project不能为空");
  128. }
  129. if($is_project==1){
  130. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  131. if($projectNo===""){
  132. return error_show(1002,"参数projectNo不能为空");
  133. }
  134. }
  135. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  136. if($khNo===""){
  137. return error_show(1002,"参数khNo不能为空");
  138. }
  139. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  140. if($companyNo===""){
  141. return error_show(1002,"参数companyNo不能为空");
  142. }
  143. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  144. if($endtime===""){
  145. return error_show(1002,"参数endtime不能为空");
  146. }
  147. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  148. "";
  149. if($platform_code===""){
  150. return error_show(1002,"参数platform_code不能为空");
  151. }
  152. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  153. if($ladder==""){
  154. return error_show(1005,"参数ladder不能为空");
  155. }
  156. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  157. if($token==''){
  158. return error_show(105,"参数token不能为空");
  159. }
  160. $user =GetUserInfo($token);
  161. if(empty($user)||$user['code']!=0){
  162. return error_show(102,"用户数据不存在");
  163. }
  164. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  165. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  166. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  167. $zxNo=makeNo("ZX");
  168. Db::startTrans();
  169. try{
  170. $data=[
  171. "zxNo"=>$zxNo,
  172. "createrid"=>$createrid,
  173. "creater"=>$creater,
  174. "is_project"=>$is_project,
  175. "projectNo"=>isset($projectNo) ? $projectNo:"",
  176. "khNo"=>$khNo,
  177. "companyNo"=>$companyNo,
  178. "endtime"=>$endtime,
  179. "salesman"=>$creater,
  180. "platform_code"=>$platform_code,
  181. "saleid"=>$createrid,
  182. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  183. "status"=>0,
  184. "is_del"=>0,
  185. "addtime"=>date("Y-m-d H:i:s"),
  186. "updatetime"=>date("Y-m-d H:i:s"),
  187. ];
  188. $zx = Db::name("consult_order")->insert($data);
  189. if($zx){
  190. //判断是否是项目,且该项目是否存在台账记录中
  191. if($is_project==1) $stand_exists=Db::name('standing_book')->field('id')->where('projectNo',$projectNo)->find();
  192. foreach ($ladder as $value){
  193. $infoNo=makeNo("IF");
  194. $specinfo=[];
  195. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  196. foreach ($value["specinfo"] as $v){
  197. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  198. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  199. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  200. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  201. $specinfo[]=$v;
  202. }
  203. }
  204. $info=[
  205. "infoNo"=>$infoNo,
  206. "zxNo"=>$zxNo,
  207. "spuCode"=>"",
  208. "good_name"=>$value['good_name'],
  209. "good_img"=>$value['good_img'],
  210. "cat_id"=>$value['cat_id'],
  211. "unit"=>$value['unit'],
  212. "brand_id"=>$value['brand_id'],
  213. "arrival_time"=>$value['arrival_time'],
  214. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  215. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  216. "is_addrs"=>$value['is_addrs'],
  217. "is_custom"=>$value['is_custom'],
  218. "metal_id"=>$value['metal_id'],
  219. "config"=>isset($value['config'])?$value['config']:"",
  220. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  221. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  222. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  223. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  224. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  225. "budget_price"=>$value['budget_price'],
  226. "num"=>$value['num'],
  227. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  228. "use_desc"=>$value['use_desc'],
  229. "remark"=>$value['remark'],
  230. "status"=>1,
  231. "is_del"=>0,
  232. "addtime"=>date("Y-m-d H:i:s"),
  233. "updatetime"=>date("Y-m-d H:i:s"),
  234. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  235. ];
  236. $up = Db::name("consult_info")->insert($info);
  237. if(!$up){
  238. Db::rollback();
  239. return error_show(1004,'添加失败');
  240. }else{
  241. //修改状态,添加待办
  242. ActionLog::logAdd($this->post['token'], [
  243. "order_code" => $infoNo,//咨询单详情编号
  244. "status" => 1,//这里的status是之前的值
  245. "action_remark" => '',//备注
  246. "action_type" => "create"//新建create,编辑edit,更改状态status
  247. ], "ZXD", 1, $info);
  248. // ProcessOrder::AddProcess($this->post['token'], [
  249. // "order_type" => 'ZXD',
  250. // "order_code" => $infoNo,//咨询单详情编号
  251. // "order_id" => 0,
  252. // "order_status" => 1
  253. // ]);
  254. //如果存在该项目编码,更新对应的第一个竞价单编码,其他竞价单编码新增(带着项目编码)
  255. if (isset($stand_exists)) {
  256. Db::name('standing_book')
  257. ->where('id', $stand_exists['id'])
  258. ->update([
  259. 'infoNo' => $infoNo,
  260. 'updatetime' => date('Y-m-d H:i:s')
  261. ]);
  262. unset($stand_exists);//后面的竞价单编码不用更新,都是新增
  263. } else {
  264. //添加台账信息
  265. Db::name('standing_book')
  266. ->insert([
  267. 'standBookNo' => makeNo("IO"),
  268. 'projectNo' => isset($projectNo) ? $projectNo : '',
  269. 'infoNo' => $infoNo,
  270. 'companyNo' => $companyNo,
  271. 'customer_code' => $khNo,
  272. 'addtime' => date('Y-m-d H:i:s'),
  273. 'updatetime' => date('Y-m-d H:i:s')
  274. ]);
  275. }
  276. }
  277. }
  278. Db::commit();
  279. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  280. }else{
  281. Db::rollback();
  282. return error_show(1004,"新建失败");
  283. }
  284. }catch (\Exception $e){
  285. Db::rollback();
  286. return error_show(1003,$e->getMessage());
  287. }
  288. }
  289. public function zxinfo(){
  290. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  291. if($infoNo==""){
  292. return error_show(1004,"参数infoNo不能为空");
  293. }
  294. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  295. if($zxinfo==false){
  296. return error_show(1004,"未找到信息数据");
  297. }
  298. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  299. if($zxorder==false){
  300. return error_show(1004,"未找到咨询信息数据");
  301. }
  302. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  303. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  304. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  305. $zxinfo['khname']="";
  306. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  307. $zxinfo['khNo']="";
  308. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  309. $zxinfo['brand']="";
  310. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  311. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  312. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  313. $zxinfo['company']="";
  314. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  315. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  316. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  317. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  318. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  319. $zxinfo['project_name']="";
  320. $zxinfo['budget_total']="";
  321. $zxinfo['departinfo']=[];
  322. $zxinfo['unit_name']="";
  323. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  324. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  325. if($zxorder['khNo']!==""){
  326. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  327. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  328. $zxinfo['khNo']= $zxorder['khNo'];
  329. }
  330. if($zxinfo['unit']!==""){
  331. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  332. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  333. }
  334. if($zxinfo['brand_id']!==""){
  335. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  336. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  337. }
  338. if($zxorder['companyNo']!==""){
  339. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  340. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  341. }
  342. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  343. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  344. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  345. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  346. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  347. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  348. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  349. }
  350. if($zxorder['depart']>0){
  351. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  352. }
  353. if($zxorder['platform_code']>0){
  354. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  355. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  356. }
  357. return app_show(0,"获取成功",$zxinfo);
  358. }
  359. public function zxedit(){
  360. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  361. if($infoNo==""){
  362. return error_show(1004,"参数infoNo不能为空");
  363. }
  364. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  365. if($zxinfo==false){
  366. return error_show(1004,"未找到信息数据");
  367. }
  368. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  369. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  370. if($good_name==""){
  371. return error_show(1003,"参数good_name不能为空");
  372. }
  373. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  374. if($good_img==""){
  375. return error_show(1003,"参数good_img不能为空");
  376. }
  377. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  378. if($cat_id==""){
  379. return error_show(1003,"参数cat_id不能为空");
  380. }
  381. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  382. if($unit==""){
  383. return error_show(1003,"参数unit不能为空");
  384. }
  385. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  386. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  387. if($arrival_time==""){
  388. return error_show(1003,"参数arrival_time不能为空");
  389. }
  390. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  391. if($specin==""){
  392. return error_show(1003,"参数specinfo不能为空");
  393. }
  394. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  395. // if($cost_desc==""){
  396. // return error_show(1003,"参数cost_desc不能为空");
  397. // }
  398. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  399. if($is_addrs===""){
  400. return error_show(1003,"参数is_addrs不能为空");
  401. }
  402. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  403. if($is_custom===""){
  404. return error_show(1003,"参数is_custom不能为空");
  405. }
  406. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  407. if($metal_id===""){
  408. return error_show(1003,"参数metal_id不能为空");
  409. }
  410. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  411. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  412. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  413. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  414. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  415. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  416. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  417. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  418. if($num===""){
  419. return error_show(1003,"参数num不能为空");
  420. }
  421. if($budget_price===""){
  422. return error_show(1003,"参数budget_price不能为空");
  423. }
  424. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  425. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  426. if($use_desc==""){
  427. return error_show(1003,"参数use_desc不能为空");
  428. }
  429. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  430. if($remark==""){
  431. return error_show(1003,"参数remark不能为空");
  432. }
  433. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  434. if($endtime==""){
  435. return error_show(1003,"参数endtime不能为空");
  436. }
  437. if($metal_id!=0){
  438. if($config==""){
  439. return error_show(1003,"参数config不能为空");
  440. }
  441. if($other_config==""){
  442. return error_show(1003,"参数other_config不能为空");
  443. }
  444. if($specs_weight===""){
  445. return error_show(1003,"参数specs_weight不能为空");
  446. }
  447. if($gold_price===""){
  448. return error_show(1003,"参数gold_price不能为空");
  449. }
  450. }
  451. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  452. if($token==''){
  453. return error_show(102,"参数token不能为空");
  454. }
  455. $user =GetUserInfo($token);
  456. if(empty($user)||$user['code']!=0){
  457. return error_show(105,"用户数据不存在");
  458. }
  459. $specinfo=[];
  460. foreach ($specin as $v){
  461. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  462. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  463. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  464. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  465. $specinfo[]=$v;
  466. }
  467. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  468. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  469. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  470. Db::startTrans();
  471. try{
  472. $innew =makeNo("IF");
  473. $info=[
  474. "infoNo"=>$innew,
  475. "zxNo"=>$zxinfo['zxNo'],
  476. "spuCode"=>"",
  477. "good_name"=>$good_name,
  478. "good_img"=>$good_img,
  479. "cat_id"=>$cat_id,
  480. "unit"=>$unit,
  481. "brand_id"=>$brand_id,
  482. "arrival_time"=>$arrival_time,
  483. "specinfo"=>json_encode($specinfo),
  484. // "color"=>$color,
  485. // "material"=>$material,
  486. "cost_desc"=>$cost_desc,
  487. "is_addrs"=>$is_addrs,
  488. "is_custom"=>$is_custom,
  489. "metal_id"=>$metal_id,
  490. "config"=>$config,
  491. "other_config"=>$other_config,
  492. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  493. "gold_price"=>$gold_price===""? 0 : $gold_price,
  494. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  495. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  496. "budget_price"=>$budget_price,
  497. "num"=>$num,
  498. "pgNo"=>$pgNo,
  499. "use_desc"=>$use_desc,
  500. "remark"=>$remark,
  501. "status"=>1,
  502. "is_del"=>0,
  503. "addtime"=>date("Y-m-d H:i:s"),
  504. "updatetime"=>date("Y-m-d H:i:s"),
  505. 'bargain_status'=>1,
  506. 'enclosure_file'=>$enclosure_file
  507. ];
  508. $up = Db::name("consult_info")->insert($info);
  509. if($up){
  510. //操作记录
  511. ActionLog::logAdd($this->post['token'], [
  512. "order_code" => $innew,//咨询单详情编号
  513. "status" => 1,//这里的status是之前的值
  514. "action_remark" => '',//备注
  515. "action_type" => "edit"//新建create,编辑edit,更改状态status
  516. ], "ZXD", 1, $this->post);
  517. // ProcessOrder::AddProcess($this->post['token'], [
  518. // "order_type" => 'ZXD',
  519. // "order_code" => $innew,//咨询单详情编号
  520. // "order_id" => 0,
  521. // "order_status" => 1
  522. // ]);
  523. if (!empty($bidlist)){
  524. foreach ($bidlist as $value){
  525. unset($value['id']);
  526. $value['infoNo']=$innew;
  527. $value['bidNo']=makeNo("BD");
  528. $value['spuCode']=makeNo("SKU");
  529. $value['status'] =0;
  530. $value['updatetime'] =date("Y-m-d H:i:s");
  531. $in = Db::name("consult_bids")->insert($value);
  532. if($in==false){
  533. Db::rollback();
  534. return error_show(1004,"反馈商品新建失败");
  535. }
  536. ActionLog::logAdd($this->post['token'], [
  537. "order_code" => $innew,//咨询单详情编号
  538. "status" => 1,//这里的status是之前的值
  539. "action_remark" => '',//备注
  540. "action_type" => "edit"//新建create,编辑edit,更改状态status
  541. ], "FKD", 1, $this->post);
  542. }
  543. }
  544. $zxinfo["bargain_status"] =1;
  545. $zxinfo["bargain_code"] =$innew;
  546. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  547. $bar=Db::name("consult_info")->save($zxinfo);
  548. if($bar==false){
  549. Db::rollback();
  550. return error_show(1004,"反馈商品更新失败");
  551. }else{
  552. //修改状态,添加待办
  553. ActionLog::logAdd($this->post['token'], [
  554. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  555. "status" => $zxinfo['status'],//这里的status是之前的值
  556. "action_remark" => '',//备注
  557. "action_type" => "edit"//新建create,编辑edit,更改状态status
  558. ], "ZXD", $zxinfo['status'], $zxinfo);
  559. }
  560. //更新consule_order记录
  561. $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,
  562. 'updatetime'=>date('Y-m-d H:i:s')]);
  563. if($op==false){
  564. Db::rollback();
  565. return error_show(1004,'咨询单结束时间更新失败');
  566. }
  567. //维护台账记录
  568. $insert_standing_book_data=[
  569. 'standBookNo'=>makeNo('IO'),
  570. 'infoNo'=>$innew,
  571. 'addtime' => date('Y-m-d H:i:s'),
  572. 'updatetime' => date('Y-m-d H:i:s')
  573. ];
  574. $temp_project = Db::name('consult_order')->field('id,projectNo,khNo,companyNo')->where(['zxNo'=>$zxinfo['zxNo'], 'is_del'=>0])->find();
  575. if(!empty($temp_project)){
  576. $insert_standing_book_data['projectNo']=$temp_project['projectNo'];
  577. $insert_standing_book_data['companyNo']=$temp_project['companyNo'];
  578. $insert_standing_book_data['customer_code']=$temp_project['khNo'];
  579. }
  580. Db::name('standing_book')->insert($insert_standing_book_data);
  581. Db::commit();
  582. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  583. }
  584. }catch (\Exception $e){
  585. Db::rollback();
  586. return error_show(1004,$e->getMessage());
  587. }
  588. }
  589. //** 发布竞标任务 */
  590. public function bargain(){
  591. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  592. if($infoNo==""){
  593. return error_show(1004,"参数infoNo不能为空");
  594. }
  595. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  596. if($zxinfo==false){
  597. return error_show(1004,"未找到信息数据");
  598. }
  599. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  600. if($status===""){
  601. return error_show(1004,"参数status不能为空");
  602. }
  603. // if($status==1&&$zxinfo['status']>1){
  604. // $zxinfo['bargain_num']=+1;
  605. // }
  606. $old_zxinfo_status = $zxinfo['status'];
  607. $zxinfo['status']=$status;
  608. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  609. $up = Db::name("consult_info")->save($zxinfo);
  610. if($up){
  611. //修改状态,添加待办
  612. ActionLog::logAdd($this->post['token'], [
  613. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  614. "status" => $old_zxinfo_status,//这里的status是之前的值
  615. "action_remark" => '',//备注
  616. "action_type" => "status"//新建create,编辑edit,更改状态status
  617. ], "ZXD", $zxinfo['status'], $zxinfo);
  618. return app_show(0,"状态更新成功");
  619. }else{
  620. return error_show(1003,"状态更新失败");
  621. }
  622. }
  623. //反馈商品添加
  624. public function feadback(){
  625. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  626. if($infoNo==""){
  627. return error_show(1002,"参数infoNo不能为空");
  628. }
  629. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  630. if($zxinfo==false){
  631. return error_show(1003,"未找到信息数据");
  632. }
  633. if($zxinfo['status']!=1){
  634. return error_show(1004,"任务未进行");
  635. }
  636. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  637. if($zx==false){
  638. return error_show(1003,"未找咨询信息数据");
  639. }
  640. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  641. if($pname==""){
  642. return error_show(1002,"参数pname不能为空");
  643. }
  644. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  645. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  646. if($cat_id==""){
  647. return error_show(1002,"参数cat_id不能为空");
  648. }
  649. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  650. if($specin==""){
  651. return error_show(1003,"参数specinfo不能为空");
  652. }
  653. $specinfo=[];
  654. foreach ($specin as $v){
  655. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  656. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  657. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  658. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  659. $specinfo[]=$v;
  660. }
  661. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  662. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  663. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  664. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  665. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  666. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  667. :"";
  668. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  669. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  670. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  671. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  672. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  673. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  674. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  675. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  676. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  677. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
  678. $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  679. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  680. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
  681. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  682. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
  683. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
  684. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  685. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  686. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  687. if($nake_fee==="" ){
  688. return error_show(1004,"参数nake_fee不能为空");
  689. }
  690. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  691. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  692. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  693. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  694. if($delivery_place==''){
  695. return error_show(1002,"参数delivery_place不能为空");
  696. }
  697. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  698. if($token==''){
  699. return error_show(1002,"参数token不能为空");
  700. }
  701. $user =GetUserInfo($token);
  702. if(empty($user)||$user['code']!=0){
  703. return error_show(1005,"用户数据不存在");
  704. }
  705. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  706. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  707. $bidNo=makeNo("BD");
  708. $spucode=makeNo("SKU");
  709. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  710. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  711. //部分参数的大小校验
  712. $vali = Validate::rule([
  713. 'expire_day|有效时长'=>'require|elt:214748364',
  714. 'delivery_day|物流时长'=>'require|elt:214748364',
  715. 'work_day|生产工期'=>'require|elt:214748364',
  716. 'weight|总重量'=>'require|max:10',
  717. ]);
  718. $temp = [
  719. 'expire_day'=>$expire_day,
  720. 'delivery_day'=>$delivery_day,
  721. 'work_day'=>$work_day,
  722. 'weight'=>$weight,
  723. ];
  724. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  725. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  726. $cat_top_list = made($cat_id);
  727. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  728. if ($is_gold_price == 1 && $cat_top_id == 6) {
  729. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  730. ->find();
  731. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  732. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  733. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  734. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  735. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  736. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  737. $saleprice = $total_fee/ (1 - $budget);
  738. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  739. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) /$good_weight - $gold["price"];
  740. }else{
  741. if($nake_fee){
  742. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight +
  743. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  744. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  745. }else{
  746. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) /
  747. (1 - $budget);
  748. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
  749. }
  750. }
  751. $data=[
  752. "bidNo"=>$bidNo,
  753. "infoNo"=>$infoNo,
  754. "zxNo"=>$zxinfo['zxNo'],
  755. "spuCode"=>$spucode,
  756. "good_name"=>$pname,
  757. "brand_id"=>$brandid,
  758. "cat_id"=>$cat_id,
  759. "specinfo"=>json_encode($specinfo),
  760. "unit_id"=>$unit_id,
  761. "cost_desc"=>$cost_desc,
  762. "work_day"=>$work_day,
  763. "delivery_day"=>$delivery_day,
  764. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  765. "expire_day"=>$expire_day,
  766. "origin_place"=>$origin_place,
  767. "supplierNo"=>$supplierNo,
  768. "pay_way"=>$pay_way,
  769. "tax"=>$tax,
  770. "send_way"=>$send_way,
  771. "metal_id"=>$metal_id,
  772. "is_gold_price"=>$is_gold_price,
  773. "config"=>$config,
  774. "other_config"=>$other_config,
  775. "weight"=>$weight,
  776. "good_weight"=>$good_weight,
  777. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  778. "is_diff"=>$is_diff,
  779. "demo_fee"=>$demo_fee,
  780. "delivery_fee"=>$delivery_fee,
  781. "open_fee"=>$open_fee,
  782. "pakge_fee"=>$pakge_fee,
  783. "nake_fee"=>$nake_fee,
  784. "mark_fee"=>$mark_fee,
  785. "cert_fee"=>$cert_fee,
  786. "cost_fee"=>$cost_fee,
  787. "total_fee"=>$total_fee,
  788. "supply_area"=>$supply_area,
  789. "remark"=>$remark,
  790. "sale_price"=>$saleprice,
  791. "sale_cost_fee"=>$sale_cost_fee,
  792. "origin_cost_fee"=>$sale_cost_fee,
  793. "origin_price"=>$saleprice,
  794. "createrid"=>$createrid,
  795. "creater"=>$creater,
  796. "status"=>$zxinfo['status']==1 ?1 :2,
  797. "is_del"=>0,
  798. "addtime"=>date("Y-m-d H:i:s"),
  799. "updatetime"=>date("Y-m-d H:i:s"),
  800. 'delivery_place'=>$delivery_place//发货地
  801. ];
  802. Db::startTrans();
  803. try{
  804. $insert= Db::name("consult_bids")->insert($data);
  805. if($insert){
  806. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  807. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  808. if($projectinfo==false){
  809. Db::rollback();
  810. return error_show(1006,"未找到项目信息");
  811. }
  812. $temp=[];
  813. $temp['spuCode']=$spucode;
  814. $temp['skuCode']="";
  815. $temp['pgNo']=$zxinfo['pgNo'];
  816. $temp['projectNo']=$zx['projectNo'];
  817. $temp['good_name']=$pname;
  818. $temp['good_type']=$projectinfo['good_type'];
  819. $temp['data_source']=2;
  820. $temp['cat_id']=$cat_id;
  821. $temp['budget_price']=$projectinfo['budget_price'];
  822. $temp['sale_price']=$saleprice;
  823. $temp['origin_price']=$total_fee;
  824. $temp['num']=$zxinfo['num'];
  825. $temp['status']=0;
  826. $temp['is_del']=0;
  827. $temp['creater']=$creater;
  828. $temp['createrid']=$createrid;
  829. $temp['addtime']=date("Y-m-d H:i:s");
  830. $temp['updatetime']=date("Y-m-d H:i:s");
  831. $nu = Db::name("project_feedback")->insert($temp);
  832. if($nu==false){
  833. Db::rollback();
  834. return error_show(1006,"项目反馈失败");
  835. }else{
  836. $old_projectinfo_status = $projectinfo['status'];
  837. $projectinfo['status']=2;
  838. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  839. $up = Db::name("project_info")->save($projectinfo);
  840. if($up){
  841. //修改状态,添加待办,只记录动作
  842. ActionLog::logAdd($this->post['token'], [
  843. "order_code" => $projectinfo['pgNo'],//编码
  844. "status" => $old_projectinfo_status,//这里的status是之前的值
  845. "action_remark" => '',//备注
  846. "action_type" => "status"//新建create,编辑edit,更改状态status
  847. ], "PRI", 2, $projectinfo);
  848. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  849. ->count();
  850. if($count==0){
  851. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  852. if($projetc!=false){
  853. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  854. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  855. if($proc==false){
  856. Db::rollback();
  857. return error_show(1006,"项目反馈失败");
  858. }else{
  859. //修改状态,添加待办
  860. ActionLog::logAdd($this->post['token'], [
  861. "order_code" => $projetc['projectNo'],//项目编码
  862. "status" => 1,//这里的status是之前的值
  863. "action_remark" => '',//备注
  864. "action_type" => "status"//新建create,编辑edit,更改状态status
  865. ], "PRO", 2, $projetc);
  866. ProcessOrder::AddProcess($this->post['token'], [
  867. "order_type" => 'PRO',
  868. "order_code" => $projetc['projectNo'],
  869. "order_id" => $projetc['id'],
  870. "order_status" => 2,"before_status"=>1
  871. ]);
  872. }
  873. }
  874. }
  875. }
  876. }
  877. }
  878. Db::commit();
  879. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  880. }else{
  881. Db::rollback();
  882. return error_show(1006,"反馈失败");
  883. }
  884. }catch (\Exception $e){
  885. Db::rollback();
  886. return error_show(1006,$e->getMessage());
  887. }
  888. }
  889. //反馈商品详情
  890. public function feadinfo(){
  891. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  892. if($bidNo==""){
  893. return error_show(1004,"参数bidNo不能为空");
  894. }
  895. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  896. if($info==false){
  897. return error_show(1004,"未找到商品数据");
  898. }
  899. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  900. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  901. $info['cat_info'] = made($info['cat_id'],[]);
  902. $info['noble_weight'] = $info['good_weight'];
  903. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  904. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  905. if($info['brand_id']!=0){
  906. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  907. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  908. }else{
  909. $info["brand_name"]="";
  910. $info["brand_id"]="";
  911. }
  912. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  913. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  914. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  915. $god=[
  916. "metal_id"=>$info['metal_id'],
  917. "weight"=>$info["good_weight"],
  918. "demo_fee"=>$info["demo_fee"],
  919. "delivery_fee"=>$info["delivery_fee"],
  920. "open_fee"=>$info["open_fee"],
  921. "packing_fee"=>$info["pakge_fee"],
  922. "mark_fee"=>$info["mark_fee"],
  923. "nake_fee"=>$info["nake_fee"],
  924. "cert_fee"=>$info["cert_fee"],
  925. "cost_fee"=>$info["cost_fee"],
  926. "num"=>$bidinfo["num"],
  927. ];
  928. if($info['is_gold_price']==1){
  929. $price = GoldPrice($god, $budget/100);
  930. $info['sale_price'] =round($price,2);
  931. }
  932. $info['specinfo'] = json_decode($info['specinfo'],true);
  933. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  934. if($info['delivery_place']!=""){
  935. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['delivery_place']);
  936. }
  937. $info['delivery_place_cn']=GetAddr(json_encode($place));
  938. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  939. if($info['origin_place']!=""){
  940. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['origin_place']);
  941. }
  942. $info['origin_place_cn']=GetAddr(json_encode($place));
  943. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  944. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  945. $info['bargain'] =$bargain;
  946. $info['good_img'] = explode(',',$info['good_img']);
  947. return app_show(0,"获取成功",$info);
  948. }
  949. //反馈商品编辑
  950. public function feededit(){
  951. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  952. if($bidNo==""){
  953. return error_show(1002,"参数bidNo不能为空");
  954. }
  955. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  956. if($bidinfo==false){
  957. return error_show(1003,"未找到信息数据");
  958. }
  959. if($bidinfo['status']>=5){
  960. return error_show(1004,"咨询单已确认无法修改");
  961. }
  962. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  963. if($zxinfo==false){
  964. return error_show(1003,"未找到信息数据");
  965. }
  966. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  967. if($zx==false){
  968. return error_show(1003,"未找咨询信息数据");
  969. }
  970. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  971. if($pname==""){
  972. return error_show(1002,"参数pname不能为空");
  973. }
  974. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  975. // if($brandid==""){
  976. // return error_show(1002,"参数brandid不能为空");
  977. // }
  978. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  979. if($cat_id==""){
  980. return error_show(1002,"参数cat_id不能为空");
  981. }
  982. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  983. if($specin==""){
  984. return error_show(1003,"参数specinfo不能为空");
  985. }
  986. $specinfo=[];
  987. foreach ($specin as $v){
  988. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  989. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  990. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  991. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  992. $specinfo[]=$v;
  993. }
  994. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  995. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  996. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  997. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  998. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  999. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  1000. :"";
  1001. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  1002. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  1003. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  1004. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  1005. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
  1006. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  1007. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  1008. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  1009. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  1010. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
  1011. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
  1012. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
  1013. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
  1014. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
  1015. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
  1016. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  1017. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
  1018. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
  1019. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
  1020. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  1021. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1022. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  1023. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  1024. if($delivery_place==''){
  1025. return error_show(1002,"参数delivery_place不能为空");
  1026. }
  1027. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  1028. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1029. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  1030. $cat_top_list = made($cat_id);
  1031. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  1032. if ($is_gold_price == 1 && $cat_top_id == 6) {
  1033. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  1034. ->find();
  1035. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1036. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  1037. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1038. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1039. $saleprice = $total_fee / (1 - $budget);
  1040. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1041. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  1042. }else{
  1043. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee +
  1044. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  1045. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
  1046. }
  1047. Db::startTrans();
  1048. try{
  1049. $data=[
  1050. "good_name"=>$pname,
  1051. "brand_id"=>$brandid,
  1052. "cat_id"=>$cat_id,
  1053. "specinfo"=>json_encode($specinfo),
  1054. // "material"=>$material,
  1055. "unit_id"=>$unit_id,
  1056. "cost_desc"=>$cost_desc,
  1057. "work_day"=>$work_day,
  1058. "delivery_day"=>$delivery_day,
  1059. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  1060. "expire_day"=>$expire_day,
  1061. "origin_place"=>$origin_place,
  1062. "supplierNo"=>$supplierNo,
  1063. "pay_way"=>$pay_way,
  1064. "tax"=>$tax,
  1065. "send_way"=>$send_way,
  1066. "metal_id"=>$metal_id,
  1067. "is_gold_price"=>$is_gold_price,
  1068. "config"=>$config,
  1069. "other_config"=>$other_config,
  1070. "weight"=>$weight,
  1071. "good_weight"=>$noble_weight,
  1072. "is_diff"=>$is_diff,
  1073. "demo_fee"=>$demo_fee,
  1074. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  1075. "delivery_fee"=>$delivery_fee,
  1076. "open_fee"=>$open_fee,
  1077. "pakge_fee"=>$pakge_fee,
  1078. "nake_fee"=>$nake_fee,
  1079. "mark_fee"=>$mark_fee,
  1080. "cert_fee"=>$cert_fee,
  1081. "cost_fee"=>$cost_fee,
  1082. "sale_cost_fee"=>$sale_cost_fee,
  1083. "origin_cost_fee"=>$sale_cost_fee,
  1084. "total_fee"=>$total_fee,
  1085. "sale_price"=>$saleprice,
  1086. "origin_price"=>$saleprice,
  1087. "supply_area"=>$supply_area,
  1088. "remark"=>$remark,
  1089. "status"=>0,
  1090. "updatetime"=>date("Y-m-d H:i:s"),
  1091. 'delivery_place' => $delivery_place
  1092. ];
  1093. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1094. if($insert){
  1095. if($zxinfo['bargain_status']==1){
  1096. $zxinfo['bargain_status']=0;
  1097. $infoip =Db::name("consult_info")->save($zxinfo);
  1098. if($infoip==false){
  1099. Db::rollback();
  1100. return error_show(1006,"咨询信息状态更新失败");
  1101. }
  1102. }
  1103. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1104. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1105. if($projectinfo==false){
  1106. Db::rollback();
  1107. return error_show(1006,"未找到项目信息");
  1108. }
  1109. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1110. if($feed!=false) {
  1111. $feed['good_name']=$pname;
  1112. $feed['good_type']=$projectinfo['good_type'];
  1113. $feed['cat_id']=$cat_id;
  1114. $feed['sale_price']=$saleprice;
  1115. $feed['origin_price']=$total_fee;
  1116. $feed['updatetime']=date("Y-m-d H:i:s");
  1117. $temp['updatetime']=date("Y-m-d H:i:s");
  1118. $nu=Db::name("project_feedback")->save($feed);
  1119. if ($nu == false) {
  1120. Db::rollback();
  1121. return error_show(1006 , "项目反馈失败");
  1122. } else {
  1123. $old_projectinfo_status=$projectinfo['status'];
  1124. $projectinfo['status']=2;
  1125. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1126. $up=Db::name("project_info")->save($projectinfo);
  1127. if ($up) {
  1128. //修改状态,添加待办,只记录动作
  1129. ActionLog::logAdd($this->post['token'] , [
  1130. "order_code"=>$projectinfo['pgNo'] ,//编码
  1131. "status"=>$old_projectinfo_status ,//这里的status是之前的值
  1132. "action_remark"=>'' ,//备注
  1133. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1134. ] , "PRI" , 2 , $projectinfo
  1135. );
  1136. $count=Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->count();
  1137. if ($count == 0) {
  1138. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1139. $project_id=Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->value('id' , 0);
  1140. if ($project_id) {
  1141. $proc=Db::name("project")->where(["id"=>$project_id])->update(["status"=>2 , "updatetime"=>date("Y-m-d H:i:s")]);
  1142. if ($proc == false) {
  1143. Db::rollback();
  1144. return error_show(1006 , "项目反馈失败");
  1145. } else {
  1146. //修改状态,添加待办
  1147. ActionLog::logAdd($this->post['token'] , [
  1148. "order_code"=>$projectinfo['projectNo'] ,//项目编码
  1149. "status"=>1 ,//这里的status是之前的值
  1150. "action_remark"=>'' ,//备注
  1151. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1152. ] , "PRO" , 2 , $this->post
  1153. );
  1154. ProcessOrder::AddProcess($this->post['token'] , [
  1155. "order_type"=>'PRO' ,
  1156. "order_code"=>$projectinfo['projectNo'] ,
  1157. "order_id"=>$project_id ,
  1158. "order_status"=>2 , "before_status"=>1
  1159. ]
  1160. );
  1161. }
  1162. }
  1163. }
  1164. }
  1165. }
  1166. }
  1167. }
  1168. Db::commit();
  1169. return app_show(0,"编辑成功");
  1170. }else{
  1171. Db::rollback();
  1172. return error_show(1004,"编辑失败");
  1173. }
  1174. }catch (\Exception $e){
  1175. Db::rollback();
  1176. return error_show(1004,$e->getMessage());
  1177. }
  1178. }
  1179. //生成议价单
  1180. public function bargain_add(){
  1181. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1182. if($bidNo===""){
  1183. return error_show(1004,"参数bidNo不能为空");
  1184. }
  1185. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1186. if($info==false){
  1187. return error_show(1004,"未找到商品数据");
  1188. }
  1189. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1190. if($consult==false){
  1191. return error_show(1004,"未找到咨询数据");
  1192. }
  1193. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1194. if($bargain_price===""){
  1195. return error_show(1004,"参数bargain_price不能为空");
  1196. }
  1197. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1198. if($info['is_gold_price']==1){
  1199. if($cost_price==""){
  1200. return error_show(1004,"参数cost_price不能为空");
  1201. }
  1202. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1203. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1204. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1205. ->find();
  1206. $bargain_price = ($info['demo_fee']/$consult['num']+$info['delivery_fee']+$info['open_fee']/$consult['num']+$info['good_weight'] * $gold["price"] + $cost_price *$info['good_weight']+$info['pakge_fee']+$info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1207. }
  1208. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1209. // if($bargain_reason===""){
  1210. // return error_show(1004,"参数bargain_reason不能为空");
  1211. // }
  1212. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1213. if($infos==false){
  1214. return error_show(1004,"未找到商品数据");
  1215. }
  1216. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1217. return error_show(1004,"咨询单招标未结束或已确认商品");
  1218. }
  1219. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1220. if($token==''){
  1221. return error_show(105,"参数token不能为空");
  1222. }
  1223. $user =GetUserInfo($token);
  1224. if(empty($user)||$user['code']!=0){
  1225. return error_show(1002,"用户数据不存在");
  1226. }
  1227. //新增两个字段
  1228. //议价备注
  1229. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1230. //议价原因id
  1231. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1232. if ($result_info_id != '') {
  1233. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1234. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1235. }
  1236. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1237. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1238. $bargainNo =makeNo("BA");
  1239. Db::startTrans();//::todo 金价 毛利计算
  1240. try{
  1241. $data=[
  1242. "bidsNo"=>$bidNo,
  1243. "infoNo"=>$info['infoNo'],
  1244. "zxNo"=>$info['zxNo'],
  1245. "bargainNo"=>$bargainNo,
  1246. "bargain_type"=>1,
  1247. "bargain_reason"=>$bargain_reason,
  1248. "sale_price"=>$info['sale_price'],
  1249. "cost_before_price"=>$info['sale_cost_fee'],
  1250. "cost_after_price"=>$cost_price,
  1251. "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],2),
  1252. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1253. "after_price"=>$bargain_price,
  1254. "exam_info"=>"",
  1255. "status"=>0,
  1256. "is_del"=>0,
  1257. "creater"=>$creater,
  1258. "createrid"=>$createrid,
  1259. "addtime"=>date("Y-m-d H:i:s"),
  1260. "updatetime"=>date("Y-m-d H:i:s"),
  1261. 'bargain_remark'=>$bargain_remark,
  1262. 'result_info_id'=>$result_info_id,
  1263. ];
  1264. $int = Db::name("bargain_order")->insert($data);
  1265. if($int){
  1266. //修改状态,添加待办
  1267. ActionLog::logAdd($this->post['token'], [
  1268. "order_code" => $bargainNo,//咨询单详情编号
  1269. "status" => 0,//这里的status是之前的值
  1270. "action_remark" => '',//备注
  1271. "action_type" => "status"//新建create,编辑edit,更改状态status
  1272. ], "YJD", $data['status'], $data);
  1273. ProcessOrder::AddProcess($this->post['token'], [
  1274. "order_type" => 'YJD',
  1275. "order_code" => $bargainNo,
  1276. "order_id" =>Db::name("bargain_order")->getLastInsID(),
  1277. "order_status" =>0,"before_status"=>0
  1278. ]);
  1279. $odlstatus=$info['status'];
  1280. $info['status']=3;
  1281. $info['updatetime']=date("Y-m-d H:i:s");
  1282. $up =Db::name("consult_bids")->save($info);
  1283. if($up){
  1284. //修改状态,添加待办
  1285. ActionLog::logAdd($this->post['token'], [
  1286. "order_code" => $bidNo,//咨询单详情编号
  1287. "status" => $odlstatus,//这里的status是之前的值
  1288. "action_remark" => '',//备注
  1289. "action_type" => "status"//新建create,编辑edit,更改状态status
  1290. ], "FKD", $info['status'], $info);
  1291. $old_infos_status = $infos['status'];
  1292. $infos['status']=3;
  1293. $infos['updatetime']=date("Y-m-d H:i:s");
  1294. $ups =Db::name("consult_info")->save($infos);
  1295. if($ups){
  1296. //修改状态,添加待办
  1297. ActionLog::logAdd($this->post['token'], [
  1298. "order_code" => $infos['infoNo'],//咨询单详情编号
  1299. "status" => $old_infos_status,//这里的status是之前的值
  1300. "action_remark" => '',//备注
  1301. "action_type" => "status"//新建create,编辑edit,更改状态status
  1302. ], "ZXD", $infos['status'], $infos);
  1303. //维护台账信息
  1304. Db::name('standing_book')->where('infoNo', $info['infoNo'])->update(['bargainNo' => $bargainNo,'updatetime' => date('Y-m-d H:i:s')]);
  1305. Db::commit();
  1306. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1307. }
  1308. }
  1309. }
  1310. Db::rollback();
  1311. return error_show(1004,"议价单新建失败");
  1312. }catch (\Exception $e){
  1313. Db::rollback();
  1314. return error_show(1004,$e->getMessage());
  1315. }
  1316. }
  1317. //选择商品
  1318. public function bids_check(){
  1319. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1320. if($bidNo===""){
  1321. return error_show(1004,"参数bidNo不能为空");
  1322. }
  1323. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1324. if($info==false){
  1325. return error_show(1004,"未找到商品数据");
  1326. }
  1327. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1328. if($infos==false){
  1329. return error_show(1004,"未找到商品数据");
  1330. }
  1331. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1332. return error_show(1004,"咨询单招标未结束或已确认商品");
  1333. }
  1334. Db::startTrans();
  1335. try {
  1336. $oldstattus=$info['status'];
  1337. $info['status']=6;
  1338. $info['updatetime']=date("Y-m-d H:i:s");
  1339. $bids = Db::name("consult_bids")->save($info);
  1340. if($bids){
  1341. //修改状态,添加待办
  1342. ActionLog::logAdd($this->post['token'], [
  1343. "order_code" =>$bidNo,//咨询单详情编号
  1344. "status" => $oldstattus,//这里的status是之前的值
  1345. "action_remark" => '',//备注
  1346. "action_type" => "status"//新建create,编辑edit,更改状态status
  1347. ], "FKD", $info['status'], $info);
  1348. $old_infos_status = $infos['status'];
  1349. $infos['status']=4;
  1350. $infos['updatetime']=date("Y-m-d H:i:s");
  1351. $se = Db::name("consult_info")->save($infos);
  1352. if($se){
  1353. //修改状态,添加待办
  1354. ActionLog::logAdd($this->post['token'], [
  1355. "order_code" => $infos['infoNo'],//咨询单详情编号
  1356. "status" => $old_infos_status,//这里的status是之前的值
  1357. "action_remark" => '',//备注
  1358. "action_type" => "status"//新建create,编辑edit,更改状态status
  1359. ], "ZXD", $infos['status'], $infos);
  1360. Db::name("bargain_order")->where(["bidsNo"=>$bidNo,"is_del"=>0,"status"=>[0,2,4,5,7]])
  1361. ->update(['status'=>12,"remark"=>'已选择商品,取消议价',"updatetime"=>date("Y-m-d H:i:s")]);
  1362. Db::commit();
  1363. return app_show(0,"商品确定成功");
  1364. }
  1365. }
  1366. Db::rollback();
  1367. return error_show(1004,"商品确认失败");
  1368. }catch (\Exception $e){
  1369. Db::rollback();
  1370. return error_show(1004,$e->getMessage());
  1371. }
  1372. }
  1373. //议价审核
  1374. /**
  1375. * status:
  1376. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1377. */
  1378. public function bargain_status(){
  1379. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1380. if($bargainNo===""){
  1381. return error_show(1004,"参数bargainNo不能为空");
  1382. }
  1383. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1384. if($info==false){
  1385. return error_show(1004,"未找到议价数据");
  1386. }
  1387. if($info['status']==12){
  1388. return error_show(1004,"议价单已取消");
  1389. }
  1390. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1391. if($bids==false){
  1392. return error_show(1004,"未找到商品数据");
  1393. }
  1394. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1395. if($coninfo==false){
  1396. return error_show(1004,"未找到咨询单数据");
  1397. }
  1398. if($bids['status']==6){
  1399. return error_show(1004,"咨询已选择商品");
  1400. }
  1401. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1402. if($status===''){
  1403. return error_show(1005,"参数status不能为空");
  1404. }
  1405. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1406. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1407. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1408. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1409. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1410. if($bids['is_gold_price']==1){
  1411. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1412. ->find();
  1413. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1414. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1415. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1416. $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1417. $saleprice =$total_fe / (1 - $budget);
  1418. $rate_price = $total_fe / (1 - $rate);
  1419. $money_price =$total_fe / (1 - $money_rate);
  1420. $lower_price =$total_fe / (1 - $lower_rate);
  1421. }else{
  1422. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1423. $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1424. if($bids['nake_fee']!=0){
  1425. $saleprice = ($total_fe)/ (1 - $budget);
  1426. $rate_price = ($total_fe)/ (1 - $rate);
  1427. $money_price =($total_fe)/ (1 - $money_rate);
  1428. $lower_price = ($total_fe) / (1 - $lower_rate);
  1429. }else{
  1430. $saleprice = $total_fe / (1 - $budget);
  1431. $rate_price =$total_fe/ (1 - $rate);
  1432. $money_price =$total_fe / (1 - $money_rate);
  1433. $lower_price = $total_fe/ (1 - $lower_rate);
  1434. }
  1435. }
  1436. $ra_status = $info['status'];
  1437. if($status==1){
  1438. if($info['status']==0){
  1439. if($info['after_price']<$rate_price){
  1440. $info['status']=2;
  1441. }else{
  1442. $info['status']=1;
  1443. }
  1444. }elseif($info['status']==2){
  1445. $info['status']=4;
  1446. }elseif($info['status']==4||$info['status']==5){
  1447. if($info['after_price']<$money_price){
  1448. $info['status']=7;
  1449. }else{
  1450. $info['status']=6;
  1451. }
  1452. }elseif($info['status']==7){
  1453. $info['lower_price'] =$lower_price;
  1454. if($info['after_price']<$lower_price){
  1455. $info['status']=10;
  1456. }else{
  1457. $info['status']=9;
  1458. }
  1459. }
  1460. }else{
  1461. if($info['status']==0){
  1462. $info['status']=3;
  1463. }elseif($info['status']==2){
  1464. $info['status']=4;
  1465. }elseif($info['status']==4||$info['status']==5){
  1466. $info['status']=8;
  1467. }elseif($info['status']==7){
  1468. $info['lower_price'] =$lower_price;
  1469. $info['status']=11;
  1470. }
  1471. }
  1472. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1473. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1474. if($token==''){
  1475. return error_show(105,"参数token不能为空");
  1476. }
  1477. $user =GetUserInfo($token);
  1478. if(empty($user)||$user['code']!=0){
  1479. return error_show(1002,"用户数据不存在");
  1480. }
  1481. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1482. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1483. Db::startTrans();
  1484. try{
  1485. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1486. $examinfo[]=["status"=>$status,"info_status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,
  1487. "creater"=>$creater];
  1488. // $info['status'] =$status;
  1489. $info['remark'] =$remark;
  1490. $info['exam_info']=json_encode($examinfo) ;
  1491. $info['updatetime'] =date("Y-m-d H:i:s");
  1492. $up =Db::name("bargain_order")->save($info);
  1493. if($up){
  1494. //修改状态,添加待办
  1495. ActionLog::logAdd($this->post['token'], [
  1496. "order_code" => $bargainNo,//咨询单详情编号
  1497. "status" =>$ra_status,//这里的status是之前的值
  1498. "action_remark" => '',//备注
  1499. "action_type" => "status"//新建create,编辑edit,更改状态status
  1500. ], "YJD", $info['status'], $info);
  1501. $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status];
  1502. ProcessOrder::AddProcess($token,$process);
  1503. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1504. $bidstatus=$bids['status'];
  1505. $bids['status']=5;
  1506. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1507. $bids['sale_price']=$info['after_price'];
  1508. if($bids['is_gold_price']==1){
  1509. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1510. // ->find();
  1511. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1512. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1513. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1514. $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1515. }
  1516. }
  1517. $bids['updatetime']=date("Y-m-d H:i:s");
  1518. $up =Db::name("consult_bids")->save($bids);
  1519. if($up==false){
  1520. Db::rollback();
  1521. return error_show(1004,"数据更新失败");
  1522. }
  1523. ActionLog::logAdd($this->post['token'], [
  1524. "order_code" => $info["bidsNo"],//咨询单详情编号
  1525. "status" => $bidstatus,//这里的status是之前的值
  1526. "action_remark" => '',//备注
  1527. "action_type" => "status"//新建create,编辑edit,更改状态status
  1528. ], "FKD", $bids['status'], $bids);
  1529. }
  1530. Db::commit();
  1531. return app_show(0,"更新成功");
  1532. }
  1533. }catch (\Exception $e){
  1534. Db::rollback();
  1535. return error_show(1004,$e->getMessage());
  1536. }
  1537. }
  1538. public function bargain_info(){
  1539. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1540. if($bargainNo===""){
  1541. return error_show(1004,"参数bargainNo不能为空");
  1542. }
  1543. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1544. if($info==false){
  1545. return error_show(1004,"未找到议价数据");
  1546. }
  1547. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1548. if($bidinfos==false){
  1549. return error_show(1004,"未找到商品数据");
  1550. }
  1551. $consultinfos =Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])->find();
  1552. if($consultinfos==false){
  1553. return error_show(1004,"未找到咨询商品数据");
  1554. }
  1555. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1556. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1557. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1558. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1559. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1560. $info['before_rate'] =round($info['before_rate']*100,2);
  1561. $info['sale_price'] =round($bidinfos['origin_price'],2);
  1562. $info['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1563. $info['after_rate'] = round($info['after_rate']*100,2);
  1564. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1565. if($bidinfos['brand_id']!=0){
  1566. $info['brand_id'] = $bidinfos['brand_id'];
  1567. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1568. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1569. }else{
  1570. $info["brand_name"]="";
  1571. $info["brand_id"]="";
  1572. }
  1573. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1574. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1575. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1576. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1577. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1578. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1579. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1580. $info['budget'] =$budget;
  1581. $info['rate_status'] =0; //利率状态 0 业务主管利率无法通过 1 财务主管利率无法通过 2 boos利率无法通过 3 完全通过
  1582. if($info['after_rate']>=$catinfo['rate']){
  1583. //业务主管利率
  1584. $info['rate_status'] =1;
  1585. }
  1586. elseif ($info['after_rate']>=$catinfo['money_rate']){
  1587. //财务主管利率
  1588. $info['rate_status'] =2;
  1589. }
  1590. elseif ($info['after_rate']>=$catinfo['lower_rate']){
  1591. //boss利率
  1592. $info['rate_status'] =3;
  1593. }
  1594. $god=[
  1595. "metal_id"=>$bidinfos['metal_id'],
  1596. "weight"=>$bidinfos["good_weight"],
  1597. "demo_fee"=>$bidinfos["demo_fee"],
  1598. "delivery_fee"=>$bidinfos["delivery_fee"],
  1599. "open_fee"=>$bidinfos["open_fee"],
  1600. "packing_fee"=>$bidinfos["pakge_fee"],
  1601. "mark_fee"=>$bidinfos["mark_fee"],
  1602. "nake_fee"=>$bidinfos["nake_fee"],
  1603. "cert_fee"=>$bidinfos["cert_fee"],
  1604. "cost_fee"=>$bidinfos["cost_fee"],
  1605. "num"=>$bidinfoe["num"],
  1606. ];
  1607. $info['gold_price']=0;
  1608. $info['noble_weight']=$bidinfos['good_weight'];
  1609. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1610. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1611. ->find();
  1612. $info['gold_price'] =$gold['price'];
  1613. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num'] + $bidinfos['good_weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['good_weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1614. }else{
  1615. if($bidinfos['nake_fee']!=0){
  1616. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1617. }else{
  1618. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1619. }
  1620. }
  1621. $info['cost_desc'] =$bidinfos['cost_desc'];
  1622. $info['work_day'] =$bidinfos['work_day'];
  1623. $info['delivery_day'] =$bidinfos['delivery_day'];
  1624. $info['expire_day'] =$bidinfos['expire_day'];
  1625. $info['origin_place'] =$bidinfos['origin_place'];
  1626. $info['origin_addr'] ="";
  1627. if($bidinfos['origin_place']!=''){
  1628. $code = explode(",",$bidinfos['origin_place']);
  1629. $temp=[];
  1630. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1631. $temp['city_code']=isset($code[1])?$code[1]:"";
  1632. $temp['area_code']=isset($code[2])?$code[2]:"";
  1633. $addr= GetAddr(json_encode($temp));
  1634. $info['origin_addr'] = $addr;
  1635. }
  1636. $info['supplierNo'] =$bidinfos['supplierNo'];
  1637. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1638. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1639. $info['pay_way'] =$bidinfos['pay_way'];
  1640. $info['tax'] =$bidinfos['tax'];
  1641. $info['send_way'] =$bidinfos['send_way'];
  1642. $info['metal_id'] =$bidinfos['metal_id'];
  1643. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1644. $info['config'] =$bidinfos['config'];
  1645. $info['other_config'] =$bidinfos['other_config'];
  1646. $info['weight'] =$bidinfos['weight'];
  1647. $info['good_weight'] =$bidinfos['good_weight'];
  1648. $info['is_diff'] =$bidinfos['is_diff'];
  1649. $info['demo_fee'] =$bidinfos['demo_fee'];
  1650. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1651. $info['open_fee'] =$bidinfos['open_fee'];
  1652. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1653. $info['nake_fee'] =$bidinfos['nake_fee'];
  1654. $info['mark_fee'] =$bidinfos['mark_fee'];
  1655. $info['cert_fee'] =$bidinfos['cert_fee'];
  1656. $info['cost_fee'] =$bidinfos['cost_fee'];
  1657. $info['total_fee'] =$bidinfos['total_fee'];
  1658. $info['supply_area'] =$bidinfos['supply_area'];
  1659. $info['remark'] =$bidinfos['remark'];
  1660. $info['is_addrs'] =$consultinfos['is_addrs'];
  1661. $info['is_custom'] =$consultinfos['is_custom'];
  1662. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1663. // $info['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
  1664. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1665. if($info['status']==7){
  1666. $info['lower_price'] =round($lower_price,2);
  1667. }
  1668. //获取议价原因
  1669. if ($info['result_info_id'] != 0) {
  1670. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1671. } else {
  1672. $info['result_info'] = '';
  1673. }
  1674. return app_show(0,"获取成功",$info);
  1675. }
  1676. public function bidlist(){
  1677. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1678. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1679. $where=[['is_del',"=",0]];
  1680. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1681. if ($zxNo !== "") {
  1682. $where[] = ['zxNo','like','%'.$zxNo.'%'];
  1683. }
  1684. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1685. if ($infoNo !== "") {
  1686. $where[] = ['infoNo','like','%'.$infoNo.'%'];
  1687. }
  1688. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1689. if ($bidNo !== "") {
  1690. $where[] = ['bidNo','like','%'.$bidNo.'%'];
  1691. }
  1692. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1693. if ($pgNo !== "") {
  1694. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1695. $where[] = ['infoNo','in',$bidinfo];
  1696. }
  1697. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1698. if ($bargain_status !== "") {
  1699. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1700. $where[] = ['infoNo','in',$bidinfo];
  1701. }
  1702. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1703. if ($projectNo !== "") {
  1704. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1705. ("zxNo");
  1706. $where[] = ['zxNo','in',$zxlist];
  1707. }
  1708. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1709. if($is_own==1){
  1710. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1711. if($token==""){
  1712. return error_show(101,'token不能为空');
  1713. }
  1714. $apply_id =GetUserInfo($token);
  1715. if(empty($apply_id)||$apply_id['code']!=0){
  1716. return error_show(1002,"申请人数据不存在");
  1717. }
  1718. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1719. $where[]=['createrid',"=",$rm];
  1720. }
  1721. $count = Db::name('consult_bids')->where($where)->count();
  1722. $total = ceil($count / $size);
  1723. $page = $page >= $total ? $total : $page;
  1724. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1725. $data=[];
  1726. foreach ($list as $value){
  1727. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1728. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1729. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1730. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1731. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1732. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1733. if($value['brand_id']!=0){
  1734. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1735. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1736. }else{
  1737. $value["brand_name"]="";
  1738. $value["brand_id"]="";
  1739. }
  1740. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1741. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1742. $god=[
  1743. "metal_id"=>$value['metal_id'],
  1744. "weight"=>$value["good_weight"],
  1745. "demo_fee"=>$value["demo_fee"],
  1746. "delivery_fee"=>$value["delivery_fee"],
  1747. "open_fee"=>$value["open_fee"],
  1748. "packing_fee"=>$value["pakge_fee"],
  1749. "mark_fee"=>$value["mark_fee"],
  1750. "nake_fee"=>$value["nake_fee"],
  1751. "cert_fee"=>$value["cert_fee"],
  1752. // "cost_fee"=>$value["cost_fee"],
  1753. "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
  1754. //暂时注掉,搞不清楚原因@吴广广
  1755. "num"=>$bidinfo["num"],
  1756. ];
  1757. $top_cat = made($value['cat_id']);
  1758. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:0;
  1759. if($value['is_gold_price']==1 && $top_cat_id==6 ){
  1760. $price = GoldPrice($god, $budget/100);
  1761. $value['sale_price'] = round($price,2);
  1762. $value['origin_price'] = $value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_price"]:
  1763. $value["origin_price"];
  1764. }
  1765. $value['cost_fee'] =$value['origin_cost_fee'];
  1766. $value['specinfo'] = json_decode($value['specinfo'],true);
  1767. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1768. $value['bargain_status']=$bidinfo['bargain_status'];
  1769. //reject驳回原因,status==5表示驳回
  1770. $value['reject']=[];
  1771. if ($value['status'] >=5) {
  1772. $value['reject'] = Db::name('bargain_order')
  1773. ->field('id,remark,status')
  1774. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1775. ->whereIn('status', [3,8,11])->order("id desc")
  1776. ->find();
  1777. }
  1778. //产地
  1779. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1780. if($value['delivery_place']!=""){
  1781. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['delivery_place']);
  1782. }
  1783. $value['delivery_place_cn']=GetAddr(json_encode($place));
  1784. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1785. if($value['origin_place']!=""){
  1786. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
  1787. }
  1788. $value['origin_addr']=GetAddr(json_encode($place));
  1789. // if($value['origin_place']!=''){
  1790. // $code = explode(",",$value['origin_place']);
  1791. // $temp=[];
  1792. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  1793. // $temp['city_code']=isset($code[1])?$code[1]:"";
  1794. // $temp['area_code']=isset($code[2])?$code[2]:"";
  1795. // $addr= GetAddr(json_encode($temp));
  1796. // $value['origin_addr'] = $addr;
  1797. // }
  1798. $data[] = $value;
  1799. }
  1800. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1801. }
  1802. public function feedlist(){
  1803. $where=[['is_del',"=",0]];
  1804. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1805. if ($zxNo !== "") {
  1806. $where[] = ['zxNo','=',$zxNo];
  1807. }
  1808. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1809. if ($infoNo !== "") {
  1810. $where[] = ['infoNo','=',$infoNo];
  1811. }
  1812. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1813. if ($bidNo !== "") {
  1814. $where[] = ['bidNo','=',$bidNo];
  1815. }
  1816. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1817. if ($projectNo !== "") {
  1818. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1819. ("zxNo");
  1820. $where[] = ['zxNo','in',$zxlist];
  1821. }
  1822. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1823. if($token==''){
  1824. return error_show(102,"参数token不能为空");
  1825. }
  1826. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1827. if($is_own==1){
  1828. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1829. if($token==""){
  1830. return error_show(101,'token不能为空');
  1831. }
  1832. $apply_id =GetUserInfo($token);
  1833. if(empty($apply_id)||$apply_id['code']!=0){
  1834. return error_show(1002,"申请人数据不存在");
  1835. }
  1836. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1837. $where[]=['createrid',"=",$rm];
  1838. }
  1839. $list =Db::name('consult_bids')->where($where)->select();
  1840. $data=[];
  1841. foreach ($list as $value){
  1842. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1843. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1844. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1845. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1846. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1847. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1848. if($value['brand_id']!=0){
  1849. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1850. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1851. }else{
  1852. $value["brand_name"]="";
  1853. $value["brand_id"]="";
  1854. }
  1855. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1856. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1857. $god=[
  1858. "metal_id"=>$value['metal_id'],
  1859. "weight"=>$value["good_weight"],
  1860. "demo_fee"=>$value["demo_fee"],
  1861. "delivery_fee"=>$value["delivery_fee"],
  1862. "open_fee"=>$value["open_fee"],
  1863. "packing_fee"=>$value["pakge_fee"],
  1864. "mark_fee"=>$value["mark_fee"],
  1865. "nake_fee"=>$value["nake_fee"],
  1866. "cert_fee"=>$value["cert_fee"],
  1867. "cost_fee"=>$value["cost_fee"],
  1868. "num"=>$bidinfo["num"],
  1869. ];
  1870. if ($value['is_gold_price'] == 1 ) {
  1871. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1872. ->find();
  1873. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1874. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1875. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
  1876. $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1877. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1878. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1879. }else{
  1880. if($value["nake_fee"]){
  1881. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1882. }else{
  1883. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1884. (1 - $budget);
  1885. }
  1886. }
  1887. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1888. $value['specinfo'] = json_decode($value['specinfo'],true);
  1889. $value['bargain_status']=$bidinfo['bargain_status'];
  1890. $data[]=$value;
  1891. }
  1892. return app_show(0,"获取成功",$data);
  1893. }
  1894. public function bragain_list(){
  1895. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1896. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1897. $where=[['bo.is_del',"=",0]];
  1898. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1899. if($bidsNo!=""){
  1900. $where[]=["bo.bidsNo","like","%$bidsNo%"];
  1901. }
  1902. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1903. if ($zxNo !== "") {
  1904. $where[] = ['bo.zxNo','like',"%$zxNo%"];
  1905. }
  1906. $bargainNo = isset($this->post['bargainNo']) && $this->post['bargainNo'] !== "" ? trim($this->post['bargainNo']) : "";
  1907. if ($bargainNo !== "") {
  1908. $where[] = ['bo.bargainNo','like',"%$bargainNo%"];
  1909. }
  1910. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1911. if ($status!== "") {
  1912. $where[] = ['bo.status','=',$status];
  1913. }
  1914. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1915. if ($infoNo !== "") {
  1916. $where[] = ['bo.infoNo','like',"%$infoNo%"];
  1917. }
  1918. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1919. if ($projectNo !== "") {
  1920. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1921. ("zxNo");
  1922. $where[] = ['bo.zxNo','in',$zxlist];
  1923. }
  1924. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1925. if ($pgNo !== "") {
  1926. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1927. $where[] = ['bo.infoNo','in',$bidinfo];
  1928. }
  1929. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1930. $end= isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1931. if($start!=""){
  1932. $where[]=["bo.addtime",">=",date("Y-m-d H:i:s",strtotime($start))];
  1933. }
  1934. if($end!=""){
  1935. $where[]=["bo.addtime","<=",date("Y-m-d H:i:s",strtotime($end))];
  1936. }
  1937. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  1938. if ($company_name !== "") $where[] = ["bo.createrid", 'in', get_company_item_user_by_name($company_name)];
  1939. $role=$this->checkRole();
  1940. if(!empty($role['write'])){
  1941. $where[]=["bo.createrid","in",$role['write']];
  1942. }
  1943. $count=Db::name("bargain_order")->alias('bo')->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")->where($where)->count();
  1944. $total = ceil($count / $size);
  1945. $page = $page >= $total ? $total : $page;
  1946. $list = Db::name('bargain_order')
  1947. ->alias('bo')
  1948. ->field('bo.*,u.itemid')
  1949. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  1950. ->where($where)
  1951. ->page($page, $size)
  1952. ->order('bo.addtime', 'desc')
  1953. ->cursor();
  1954. $data=[];
  1955. foreach ($list as $value){
  1956. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1957. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1958. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1959. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1960. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1961. if($bidinfos['brand_id']!=0){
  1962. $value['brand_id'] = $bidinfos['brand_id'];
  1963. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1964. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1965. }else{
  1966. $value["brand_name"]="";
  1967. $value["brand_id"]="";
  1968. }
  1969. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1970. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1971. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1972. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1973. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1974. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1975. $value['budget'] =$budget;
  1976. $god=[
  1977. "metal_id"=>$bidinfos['metal_id'],
  1978. "weight"=>$bidinfos["good_weight"],
  1979. "demo_fee"=>$bidinfos["demo_fee"],
  1980. "delivery_fee"=>$bidinfos["delivery_fee"],
  1981. "open_fee"=>$bidinfos["open_fee"],
  1982. "packing_fee"=>$bidinfos["pakge_fee"],
  1983. "mark_fee"=>$bidinfos["mark_fee"],
  1984. "nake_fee"=>$bidinfos["nake_fee"],
  1985. "cert_fee"=>$bidinfos["cert_fee"],
  1986. "cost_fee"=>$bidinfos["cost_fee"],
  1987. "num"=>$bidinfoe["num"],
  1988. ];
  1989. // if($bidinfos['is_gold_price']==1){
  1990. // $price = GoldPrice($god, $budget/100);
  1991. // }else{
  1992. // $price = GoodPrice($god, $budget/100);
  1993. // }
  1994. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1995. $value['sale_price'] =round($bidinfos['origin_price'],2);
  1996. $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1997. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1998. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  1999. $data[]=$value;
  2000. }
  2001. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  2002. }
  2003. public function crontablist(){
  2004. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  2005. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  2006. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  2007. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2008. if ($zxNo !== "") {
  2009. $where[] = ['a.zxNo','=',$zxNo];
  2010. }
  2011. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  2012. if ($salesman !== "") {
  2013. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  2014. $where[]= ["b.salesman",'like',"%$salesman%"];
  2015. }
  2016. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  2017. if ($cpName !== "") {
  2018. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  2019. $where[]= ["a.good_Name",'like',"%$cpName%"];
  2020. }
  2021. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  2022. if ($khNo !== "") {
  2023. // $where['khNo'] = $khNo;
  2024. $where[]= ["b.khNo",'like',"%$khNo%"];
  2025. }
  2026. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  2027. if ($start !="") {
  2028. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  2029. $where[]= ["a.addtime",'>=',$start];
  2030. }
  2031. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  2032. if($end !=""){
  2033. $where[]= ["a.addtime",'<=',$end];
  2034. }
  2035. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  2036. if ($status !== "") {
  2037. $where[]= ["a.status",'=',$status];
  2038. }
  2039. // $role=$this->checkRole();
  2040. // if(!empty($role['platform']) ){
  2041. // $where[]=["b.platform_code","in",$role['platform']];
  2042. // }
  2043. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  2044. ->count();
  2045. $total = ceil($count / $size);
  2046. $page = $page >= $total ? $total : $page;
  2047. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  2048. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  2049. $data=[];
  2050. foreach ($list as $value){
  2051. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  2052. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  2053. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  2054. $value['khname']="";
  2055. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  2056. true):[];
  2057. if($value['khNo']!==""){
  2058. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  2059. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  2060. }
  2061. $consult =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"createrid"=>$this->uid,"is_del"=>0])
  2062. ->find();
  2063. $consults =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"is_del"=>0])->find();
  2064. $value['is_feed'] =$consult==false?0:1;
  2065. $value['is_all_feed'] =$consults==false?0:1;
  2066. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  2067. $data[]=$value;
  2068. }
  2069. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  2070. }
  2071. //复制上面的bidlist方法,只更改排序方式
  2072. public function bidlistCopy()
  2073. {
  2074. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2075. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2076. $where = [['cb.is_del', "=", 0]];
  2077. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2078. if ($zxNo !== "") {
  2079. $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
  2080. }
  2081. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  2082. if ($infoNo !== "") {
  2083. $where[] = ['cb.infoNo', 'like', '%' . $infoNo . '%'];
  2084. }
  2085. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  2086. if ($bidNo !== "") {
  2087. $where[] = ['cb.bidNo', 'like', '%' . $bidNo . '%'];
  2088. }
  2089. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  2090. if ($pgNo !== "") {
  2091. $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
  2092. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2093. }
  2094. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  2095. if ($bargain_status !== "") {
  2096. $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
  2097. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2098. }
  2099. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  2100. if ($projectNo !== "") {
  2101. $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column
  2102. ("zxNo");
  2103. $where[] = ['cb.zxNo', 'in', $zxlist];
  2104. }
  2105. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  2106. if ($is_own == 1) {
  2107. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  2108. if ($token == "") {
  2109. return error_show(101, 'token不能为空');
  2110. }
  2111. $apply_id = GetUserInfo($token);
  2112. if (empty($apply_id) || $apply_id['code'] != 0) {
  2113. return error_show(1002, "申请人数据不存在");
  2114. }
  2115. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2116. $where[] = ['cb.createrid', "=", $rm];
  2117. }
  2118. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  2119. if ($company_name !== "") $where[] = ["cb.createrid", 'in', get_company_item_user_by_name($company_name)];
  2120. $count = Db::name('consult_bids')->alias('cb')->where($where)->count();
  2121. $total = ceil($count / $size);
  2122. $page = $page >= $total ? $total : $page;
  2123. $list = Db::name('consult_bids')
  2124. ->alias('cb')
  2125. ->field('cb.*,u.itemid')
  2126. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2127. ->where($where)
  2128. ->page($page, $size)
  2129. ->order('cb.addtime', 'desc')
  2130. ->cursor();
  2131. $data = [];
  2132. foreach ($list as $value) {
  2133. $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  2134. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2135. $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
  2136. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  2137. $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  2138. $value['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  2139. if ($value['brand_id'] != 0) {
  2140. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  2141. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  2142. } else {
  2143. $value["brand_name"] = "";
  2144. $value["brand_id"] = "";
  2145. }
  2146. $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
  2147. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  2148. $god = [
  2149. "metal_id" => $value['metal_id'],
  2150. "weight" => $value["good_weight"],
  2151. "demo_fee" => $value["demo_fee"],
  2152. "delivery_fee" => $value["delivery_fee"],
  2153. "open_fee" => $value["open_fee"],
  2154. "packing_fee" => $value["pakge_fee"],
  2155. "mark_fee" => $value["mark_fee"],
  2156. "nake_fee" => $value["nake_fee"],
  2157. "cert_fee" => $value["cert_fee"],
  2158. "cost_fee" => $value["sale_cost_fee"]!=$value["origin_cost_fee"] ? $value["sale_cost_fee"] : $value["cost_fee"],
  2159. "num" => $bidinfo["num"],
  2160. ];
  2161. if ($value['is_gold_price'] == 1) {
  2162. $price = GoldPrice($god, $budget / 100);
  2163. $value['sale_price'] = round($price, 2);
  2164. }
  2165. $value['cost_fee'] = $value['origin_cost_fee'];
  2166. $value['specinfo'] = json_decode($value['specinfo'], true);
  2167. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  2168. $value['bargain_status'] = $bidinfo['bargain_status'];
  2169. //reject驳回原因,status==5表示驳回
  2170. $value['reject'] = [];
  2171. if ($value['status'] >= 5) {
  2172. $value['reject'] = Db::name('bargain_order')
  2173. ->field('id,remark,status')
  2174. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  2175. ->whereIn('status', [3, 8, 11])->order("id desc")
  2176. ->find();
  2177. }
  2178. //产地
  2179. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2180. if ($value['delivery_place'] != "") {
  2181. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
  2182. }
  2183. $value['delivery_place_cn'] = GetAddr(json_encode($place));
  2184. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2185. if ($value['origin_place'] != "") {
  2186. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
  2187. }
  2188. $value['origin_addr'] = GetAddr(json_encode($place));
  2189. // if($value['origin_place']!=''){
  2190. // $code = explode(",",$value['origin_place']);
  2191. // $temp=[];
  2192. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  2193. // $temp['city_code']=isset($code[1])?$code[1]:"";
  2194. // $temp['area_code']=isset($code[2])?$code[2]:"";
  2195. // $addr= GetAddr(json_encode($temp));
  2196. // $value['origin_addr'] = $addr;
  2197. // }
  2198. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2199. $data[] = $value;
  2200. }
  2201. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  2202. }
  2203. }